Fixed encoding bug for sorting algo.