fixing while loops