fixed some bugs for sample gamma