fixing while-loop in IO