Broke into function. Preparing for multiprocessing.