refactored code, added model.