use better replica detection method

Fixes #1182 
See there for fuller description.