deadlock and fixes