completed implementation of samples()