Improved for loop - bug