Fix endpoint cleanup bug