Made write thread-safe