Improve safe next/end handling slightly