generalising detection code for running different data sets