Here's the source code. Hopefully it helps somebody.