Attempt to handle OPTIONS from candidate requests, and refactoring the code