More general membership testing and cleanup