Changed to newer CImg interface and fixed two regressions