Implemented generateTree