Improved window opening using waitFor()