Put the header for a source file first (and fix issues).

This allows detecting problems with the header, many of which were found and fixed.