fixed mod 4 code