fixed captureWindow method