Bugfixes found by scrutinizer