Implement Statemachine and some algorithm stuff
merge fixes