add function that use parfor instead of for when possible
changes to merge parallel and non parallel code