Better way of adding CORS headers. Better logging of errors