wrapping the state machine creator callback in an anonymous function to prevent crazy scoping