Moodle Code with optimizations