Fix bug with indexExists function