Reordered includes to avoid warnings

Move the includes of _head and _connect to the first lines of the file
to avoid the "header already sent" warnings.