reworked to sliding window implementation