Added support for custom tree output and fixed tree reader bug