refactoring for finding nodes