better detection of number of samples