Updated code, nows requires Moodle 2.5