Cosmetic improvements

Shifted some functions between gui.php and moodle_emulator.php
to make things more structured.