Refactor tree reading

This PR refactors the tree-reading.