Cleanup main function

Move various checks out of main() and into the proper subsystem.