major refactoring of node state machine