separate find last index into its own function