Move sync functions from api.py to sync.py