Added multi-threaded compatability.