issue transposing a gen~ filter patch into gen~ codebox

Zoy's icon

Hello, I'm trying to fit a gen~ regular patch filter into a codebox for a project, but seems to get an issue with the global structure. I certainly could use another filter structure but I'm still frustrated not understanding where the problem is (see patch attached). While the original patch gives a smooth filtered rendering of the input, the codebox versions output an infinitely increasing number. I tried to replicate literally the 'code' section of the original patch, then replace the History with a Delay function, but none works. Any idea?

filter_debug.maxpat
Max Patch