Fix locking bugs.