Mostly resolves bug #561, memory leaks.
Fix for (user) context-dependence of arith TO_INT/IS_INT rewriting and rewrite-divk.