Replaced obsolete end-of-list detection with new one.