Fixed some bugs in new sampling code.