More fixes in createTree function