Extract openWindow to separate function