safe close of streams