Began rewrite for multiprocessing and python 3 compatibility