bug fix for ending offset