Fix for #3281.
Fix for #3166.
Fix for #3286.
Merge pull request #3282 from Segrain/master

Bugfixes.