refactoring model and error handling