Fix #3979 and #3883