Fix mask index error