Bugfixes.

Fix for #3324, #3104, and #3230.
Partial for for #2284.