How does endpoint detection work?