Sliding window function written.