edited to for faster parallelization