factoring out mod into separate z3 function