Minor refactoring of endpoint logic