Integrating model view and controller with mainloop