Refactoring 'equals' utility method