refactoring the compareNode