refactoring nodes into a object