Moved code that emits "i" to transformToCollection.