First changes towards fixing #819. This is ready for more serious testing.
Merge branch 'fixing_819'
Fix merge conflict