Initial implementation.

I did the work on this about a year ago, but never published it.