add: use sliding window algorithm to keep order