Code quality fixes

A couple of unrelated code-quality fixes.

These fixes, together, also fix one of the tests which are currently failing.