replaced for loop with parfor loop, not sure if done correctly as runtime seems to be about the same as the for loop