Been there a few times, plan to keep visiting. Hopefully those scripts you wrote and threw away were designed and written at the highest level of professional competency.
IIRC the solution steps should be Step 1: make it work, Step 2: refactor, Step 3: optimize. I think you did Step 1: unoptimize, Step 2: undo