Implemented a fairly reliable window detection algorithm