Refine window state logic