updated version. detection allocation is almost done but need bug fixing