Fixing bugs #2719, #4659 and #5856