Added button state machine