close handle properly