updated sliding window code