Remove unused nodes from graph