bug fix: use window function