Improve debugging to use Moodle facilities, and commit properly