Improved connection handling (when lost/errors).
Added proper headers to all files.