Here's the code (if anyone's interested).