Fix headings not being closed correctly