Added code to balance large trees