Fixed issue where stream wouldn't close