Refactor check() in statemachine
Merge origin/master