Move window creation logic to method