Added cors support, better error handling