fix bugs in remove_extra_nodes and update the garbage_collector function