Fixed issues #5786, #5823 and #5841

fix #5786
fix #5823
fix #5841