Some minor restructuring for basic multiprocessing support and for easier testing