Refactor main

Restructure and refactor main.cpp (in particular main() itself)

Spaces are used here.