Refactor main

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

I like space but this is indented too much