CORS and some more refactoring