Add method to map state machine

Add method to map the state machine. Also fix some bugs.