Fixed bug when running in parallel