Bugfixes

See commit log for description.

Note that these bugs were _NOT_ caught by the unit tests, we should definitely fix that!