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