some more logging
added state machine, and debug mode