move code into library, use gt.script_dir