Fixed a bunch of errors found by phpstorm