Fixed bug in tree creation