Fix initialization to be thread-safe