fixed a bug which could cause deadlock