Refactored endpoint code.