Decided to remove the processing of <main>. Looked like a good idea but it isn't; mixing <main> and <section> for heading leads to strange HTML structures.