Better emit an end only when we're really done.
Cleaner code.