changes from Greg,fix some deadlock