Final prep for using Message Queues

- move the implementation of the main loopout of the main(0 function.
  this allows there to be several implementations of the main loop
  that do not clutter up the main function.

- need to add a main loop implementation that uses message queues
  instead of the pipe.