Fix various issues found by the PhpStorm code inspector