Add some protection against deadlocks