Added some thread safety