fixed detection code