Refactor register endpoint