Fixed a bunch of bugs with syncing

These bugs where introduced in #8 and #9. Hopefully all fixed now.