Fixes for #6864, #6840 and #6799