Refactor code + Add CORS header