added multithreading support

@saary