Example code I've posted on http://statemachina.com