Added Mutex for thread safety.