refactor into models and views