Some bugfixes in tree creation