Improving main so it can use SettingsModel.

Also splitting code into meaningful functions to be used among all application.