Initial refactoring to separate view code