Fixed a bunch of synchronization bugs