fix jIndex function