code folding
added some close protection