Make sure "out" isn't null before attempting to close it.