Added thread safety.