Implemented Gibbs sampling