Fixing window iteration code to not abort in the middle of the loop

This is a simple change, but it ensures the iteration over the windows doesn't end prematurely.