More of #6, untested, will try to commit more in ~30 mins