Move definition of with_index below

Right now is defined in the middle of two definitions of max function.
Merge pull request #1511 from guilleiguaran/with_index

Move definition of with_index below