Refactored FSM shutdown code to separate state machine callback

Signed-off-by: Paul Colomiets <paul@colomiets.name>