Fixed a few minor bugs in main