meg_pilot: cleaned up/commented code to make it more useable by non-me;