Refactored equals method