Fixes deadlock bug that occasionally occurs.