Fix a bug in sample window function.