Backport https://github.com/pommi/CGP/commit/dea39449a9e4dad52f1682af680dd9fec9b6517f
Backport https://github.com/pommi/CGP/commit/5a9db96a2b8cd89a62947049d35692d45689155b based on my patch but better
Backport https://github.com/pommi/CGP/commit/fecc70eceb3208e77b02b7ef17bef2c2b467a293