fix use of `eend` in `cleanup` function