State machine impl

----------------------
branch [[master]]