Cleaning up event listeners; refactoring for extensibility