Refactored the comparator