added end conditions to first level