Multiple bugfixes around querying

Schema upgrading now in a write-locking transaction.
Sync more stable