restructure the paralleliam code and the errors handling code