Refactoring to prepare for MBQI with integer quantification.  Minor bug fixes.