Updated code base and fixed FSM