refactored window stuff