Correct depth bounds issue in tree generation