Refactor isPair method for better readability