Code cleaning; still not working while&ifs