generalized the tgp code into a script we can call from command line