refactor equals function.