Refactor and document.