Fixing loop to have correct number of items