detection algorithm