Refactor sync

Per suggestions in issue #17, refactor sync code from preview.py and test_preview.py into separate files.