Added Gibbs code provided by Frederik Eaton