bugs fixes

Fixes to bugs found by Scrawl.