externalizing script and correctly processing command line