State machines are a great way to program; I use them for almost everything; I actually define the states inside a struct.