Old code from years ago. Putting up here in case there is anything useful in it for someone. Created together with Jason Burgett (github.com/jasbur).