improving tree creation

changes around line 65 or so