fixed next_node method