Polished the .success and .error functions
Implemented the response headers handling and improved the script. Script ready for production