add detect_end