rewrite get-headings as a reduce