added some algolism to get best window