This is all the code after a week and a bit hacking on this project. It's in a rather experimental state but should work with a little effort.