fix a few bugs and parallelize
fix parallelization