gibbs + tail recursion

fixed tail recursion, added gibbs sampling