Review and changes from Jocelyn Fiat

here I wrapped the output in a debug clause
but probably for the final version, such output code should be removed.