Refactored and allowed for command-line switches.