This reverts commit 87c5437afd273e909e0fed3389de7531d5452ea5. The commit includes several headers in the middle of a function, which breaks pretty much everything.