working on bringing this shambles up to Moodle coding standards. More to do