Fix for #3845 and #4403