Typo fix and minor refactoring of main