Refactor sync

Per suggestions in issue #17, refactor sync code from preview.py and test_preview.py into separate files.

On a side note, I don't know how to separate this pull request from the earlier request (codechat.png icon removal) -- what's your recommended process?