Refactor into smaller functions and macros.
Add documentation to new functions, and ensure they are selected, ready for editing.