Refactor main

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

This isn't indented correctly. This is correct:

```
if ((ENABLE_TESTS && cmd_args.getFlag("disable-unittests") == false)
  \t    \t    || cmd_args.getFlag("enable-unittests") == true) {
  \t    run_tests();
}
```