Bug fixes for model factory