Added CORS support for cross-domain requests, refactorings