Created main(), parse_params() functions

Refactoring for readability:
I moved all code into a main() function.
I created a parse_params() function for a chunk of the main() function.
No functionality should have changed.
This is untested.