code refine for open window