fix end condition