Fixed parallel code
Refactored code