full algorithm for Gibbs