It could use variables a bit more, I think, but there were a few bugs with expanding them, so I didn't use them. I'll fix them later on, though.
thx!
I'll put this up in a post on my blog, maybe it'll help others as well.