Improve end-point detection logic
Improve end-point detection logic
Revert "Improve end-point detection logic"

This reverts commit 5244d49ff9a13d23243f1d40750f189ff92f3e3b.
Revert "Revert "Improve end-point detection logic""

This reverts commit 3f5b52abac4bafcf7b39a22affcad1077311f0be.
Improve end-point detection logic