refactoring get-headings to use mutables variables