added gradient implementation, new flag 'optimize_polygons' for fixing eo-filling