bugfixes uncovered by smgl tests