Fixing locking that leads to hangs on startup