Refactor state internals to improve testability
PEP8 areas changed
Merge pull request #2 from kapouille/state_testability

State testability