Refactor main; add command line switches