Refactored model/view code