repaired continuous loop logic error