Improve algorithm to re-identify a window