sampler: add unit tests and fixes