Backport https://github.com/pommi/CGP/commit/216e492f32ab9a23e9b345e2bf424ba15025aec4