Implemented the tree structure with extend