Resolved many errors discovered by Moodle CodeChecker