I feel dirty for even writing this code.

I'm also adding some documentation, so when I come back to fix this
later I don't go "What the crap was I smoking this time?!".