implemented last index of fucntion