Closes streams properly.