improved peak window algorithm