solved second problem, not sure how to parallelize this one