loop index re-ordering