Bugfixes, including #347