^ generateTree function
did some small tweeks to make it work better