builds tree properly.