Applied most recent changes from our customized Moodle 2.4 code base.