try to automatically find threshold