jx_end: finalise the terminal

- Make sure the terminal is left as how we started off with.
- Add some comments for code navigation.