Changed name of "state functions" (i.e. state_shutdown) to while_shutdown, while_sleepint, etc. as I think this better reflects what they are and what they do.
Added lots of doc strings for the while_ functions for the various states.