Cancel fsm

This PR is largely the same as #139 , but removes some commits that I sneaked into other branches.
The previous PR was also made before the indent changes, which would've made merging a lot harder.
I hereby guarantee that besides the remarks above the changes are the same as in the other.