Changed order of index checks