[refactor] attachListeners and detachListeners, updated example