Moved the code for adding and removing nodes.