Initial version of get_next_node + fixed alloc bug.