beautify state machine