Basically pull patch of leont++ (RT #122722)