Event listeners are removed when no longer necessary

Changed some event listeners to `once` and added `removeAllListeners` for events that won't fire again.

Algolia was preventing graceful shutdown of node applications. This should fix it.