Some unfinished but not relevant work crept into the diff, but it's still valid (and was working for me before I posted it)