refactor comparator