Fixed freezing problem when switching windows