move the gm1 code from main in a speperate function and add support for tgx