optimized code for parallelization