convert to Model-View-Controller pattern