fix two deadlock bugs