See design-doc.txt for implementation details.