This implementation definitely has bugs and is completely untested at this point. I'm just committing the initial "assume everything works" version before I did into debugging and fixing.