This sort of problem is sometimes caused by barline-to-barline thinking. This prelude is typical of Bach's way of constructing in that the first pattern starts a semiquaver into the bar and ends on the first quaver of bar 2. Then there are 3 link notes BED#, again crossing the next bar-line before the patterning repeats. Meanwhile the LH is playing a similar pattern from Bars 2 to 3.
I once solved this problem for a pupil (temporarily) in a similar piece by snopaking out the bar lines and drawing them back in a beat later. It worked like magic until I replaced the original lines.