functions to find track end indices