Fix undefined method `each_with_index'

Replace each_with_index with simple counter to avoid error:
undefined method `each_with_index'