corrected the termination criteria