Added codes to close and release  streams.