Optimize moving window