Misc fixes, after going through PhpStorm error reporting