optimizing for modulo arithmetic