Refactoring comparator logic.