fixed ending condition