fixed a bug or two. Also tree is dynamically formed, rather than declared