Experimental and ab initio study of Mg doping in the intrinsic ferromagnetic semiconductor GdN