Added ability to make library thread safe.