Fix for invalid reference to window.length