refactored compareTo