Refactoring and optimization for Node class an related classes.