Refactor to separate view model and rendering code.