Implementing detection function