complete deadlock and fix some bugs