Fix bugs when using OpenMP