Some problem fixes found by scrutinizer