Refactoring endpoint implementation