pulled out common logic into a java statemachine api