Updated folding logic