I suspect you wanted to use topic passed to this function rather then enclosed one, because this way you'll only remove listener for the one topic and not any other it maybe registered to.