Structure the main function

This PR designates areas of the main function for initialisation, the main loop and the deinitialisation.
Targets issue #44. (by introducing another approach).