replace units.each with units.each_with_index