Refactoring to respect model-view-controller