shortend code around node operations if statements
Refactored code to shorten files further