optimize and unit test sort by field