fixed mod cases in iteration