Replaced calls to on/off with addEventListener/removeEventListener, adding log() and logEnabled