We shouldn't be re-wrapping window so much
So I put it in the top level function
We don't need the closure on window, I just added
it in to save lines