Finalize offline sync code, mainly working now.