Refactored MainCtrl.
Refactored MainCtrl. Separated chunks of code into several controllers and services.