enabled the script to be pulled in as a library by separating out
the main code