Fixes for #852, #853, #862

See the issues themselves and the commit messages for more information.