fixes to trunk 3991
(cherry picked from commit 106cab3401a3c434ab3054363a8af9315705600f)