Fixed while loop i logic