Building finite state machine for sync.