added error handling for closing the channel