added parallelized version of code, modified by Jesus Galaz