Added functionality for adding and removing listeners.