Small improvements to window context management