only connect event listeners when necessary