Looots of code fixes based on PhpStorm code inspection