Pass block instance to fix closure context

It was using `window` because the code is wrapped in a closure