Feature/state transition machine

Also, `empty` does too many magic under the hood for my taste.
This is used also in [L177-183](#diff-9f57f09a51bbdbdb8aa8380793506f44R177) and may give us some hidden problems, like not allowing '0' to be a state, or things like that.