End book properly by checking for last segment