Changed to the code from moodle