moved var g and num to global