Refactored window initialization