Added documentation to state definition, and debugging output to the state system itself.