Coded the controllers to match a real MVC pattern

Removed all procedural code and coded the controller how should be
coded.
Thanks to @paulund_ at Twitter for his advice.