Implemented exact sampling.