fixing bugs in contraction algorithm