Added ApplicationControler

Refactored code and moved a lot of code to the ApplicationController.