implement fold detection