Added a controller and moved all the application logic to it.