Fixed a strange bug which causes deadlock?