add closed handler check