fix fold bug. isolate inner fold into helper to avoid same mistake