Refactor/minor reorganization

This is a minor refactor. Each logical piece of code change was contained within a commit. This script would not previously execute without the call to main() [This may have been lost in recent refactors].