Code clean-up, and prepared for parallelization.