moved main code into its own shell script, and more changes