more rewrite using models, refactoring