Fixed GM detection code