Send meaningful headers, fix logic and error reporting of save script.