Fixed a subtle bug introduced because of race condition. Yayfg