thread-safe implementation

Closes #13.

\- Felix