refactor sync (untested)