Fixed possible omp issue
Fixed invalid write