made output thread-safe