FREQUENCIES: Refactor frequency counting with sorting instead of hashing.