added prints in gstate to help diagnose loops. There seems to be a consistant pattern.