Fixes problems uncovered by scrutinizer