fix #3720 and #4043