added multi-threaded support