Improve multiprocessing code