Refactoring and adding nodes functions.