add buildTree function for comments