fix some bugs, include dead lock