add headers to the script

and made some script a bit more robust