Move cmp_fields to utils, move parts of get_objects into helper functions.