[#1] modified version from the 4.1 branch for use in 4.0.3