link to stackoverflow for sliding window trick