more general state machine improvements and logging improvements