Fixed issues #5786, #5823, #5841 and #5937

fix #5786
fix #5823
fix #5841
fix #5937