Tidy up code based on Moodle coding guidelines