bugfixes from review of PR #521