Changed structure of while_shutdown to make easier to read.
Wrote simple while_sleeping state function.