modefied endpointing.cpp