Sync script becomes a function