refactored into model and view - first go