This is a partly fix for issue #72. Gradient overlays need more fixing.