add better index handling