Apply Sorting to Valid Codes