Separate StateMachine Client dependency

Make the state machine unaware of the client and set up event handling
in Client class. Add some unit tests.