Fix php strict standards bug, fix small performance issue, Code cleanup according to moodle codechecker