Cleanup and fix endpoint shutdown