made thread-safe [closes #5]