add closing cursor in getLatestEnd method.