Refactore compare method