Better way of making it thread safe