added membership checking loop