Updated detection algorithm