fix bugs found by scrutinizer