Adding code for sliding window mode.