Fixes to avoid deadlocks