Implementing delete_nodes function