Adding synchronization for thread-safety