- cleaned up state transition code