Detect CORS, refactor