Fix two critical synchronization bugs