Moodle js refactoring