returning correct index