Made it thread safe