changed condition for while-loop