Added leaf count end conditions.