detection code written [NOT TESTED]