Fixed bug by replacing gamma with gammaln