Tidied this into a class now.

You'll see it popping up all over the place.