Fix deadlock
Merge pull request #921 from egbertbouman/deadlock_fix

Fix deadlock