Multiple fixes

Fix for #849
Fix for #850