Add state machine.
Start to refactoring code with state patten.
Rewrite the code using state patten and observer.