Improved error handling, made it work with cloudflare