Refactor main

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

Bad indentation here