Refactor and document