fixing while loop