logic for the listener and sync part