Added global and local headers. Improved error reporting.