Fix bugs in window resizing code