Started writing gibbs algorithm