improved ggt() function