modified the code for generating basic trees from the query