Bugfixes driven by test suite