refactor find_next_node