Fixed a memory leak in the tooltips code

- Tidied the code a little