Revert "Revert "Fixed problems with resizing window""

This reverts commit 622fa67f9ede87cca0c36d321269be18db2320fd.