refactor equals method