fixing while loop for problem solution