Adding multithreading for nice speedup