modified detection algorithm.
added comment