Huge code cleanup based on PHPStorm inspections