Fixed issues found by scrutinizer