Sort some fields. Remove unused code.