Bugfixing in statemachine and improvements to pattern decision