Fix models issues
Add case when generated object is valid
Refactoring