fix a bug of i and j