fix bugs for NIG inversion and modifications for visual studio