contraction algorithm implemented