While statement bugfix