changed to more elegant sliding window