fixes to gfx code
Merge with gal's implementation