major issues fixes found by scrutinizer