Correctly handle the end of a listing