Move state machine gem into core