Adding tree query functionality.