Refactoring design
Fix window calculation