Slightly changed stopstream and error handling.