Hacking on this as I travel over the next few days. This code probably doesn't compile, it's not finished and I have to stop working on it for now.