Improved thread safety for singletons