TreeView code refactored to prototypes for performance reasons.
TreeView refactored.