Initial attempt at #7. Needs a bit more work & tests.