Sets model

Mostly related to generation of models for theory sets, but also fixes for other bugs discovered.