Fixed some deadlocks