updated sgscript, added window handle retrieval