Revert "Fixing bug #3817."

This reverts commit ad2a0308b1592c7235714a2cca926f3b55accbb2.
Fixing bug #3858 and #3817 in one stroke.