Tweaked sync code; added some ORM background stuff (can't remember why)