Changed criteria to select optimal window. Now using maximum average of ivs (or sums, which is equal)