fix bugs found with z3