getting the right index