gstate code cleanup