fixed size calculation

completely reworked the algorithm that calculates the optimal size for
the given number of elements and the window size