Change multiprocessing to pools and do minor refactoring