Refactorede window code to a new class