backporting https://github.com/webdetails/cdf/commit/afcb00e5cdfe47c8e05d9e15ef9b47f55b776981 as is has shown to be a better solution for http://redmine.webdetails.org/issues/2250, that works both on 4.x as well as on 5.0