Written for Moodle 2.6