Fixed potential issue with small number of samples