Solved the bug of inserting/freeing only the head to the graph