Refactor CreateWindow into own function