yet another attempt at fixing deadlocks, again not sure if this actually fixes anything. Issue #645 and issue #531.