change to use a command line parameter and fix substring bug