Fix model assignment error that caused invalid error to be displayed when the model type doesn't match. Miscellaneous changes and tweaks.