Add handling of end of chain