Fix detection code