refactored code to seperate initializing nodes