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