Refactor the window switching advice code