use threads to speed up processing

Depends on the thread-safety patch to work. Speedup is about 50-80% on my machine (not counting initial setup and first run).