Fixed hanging under some rare race conditions (relates to #4)