Modified code to include CCD workaround