first thread-safe version