Bug fix: close underlying streams properly.