Added thread synchronization.