State change refactoring.
Merge pull request #6 from dmirain/state_change

State change refactoring.