Major refactor for CLI script. Closes #2.