stream end and destroy functions shouldn't be inside stream data function
log data first
somewhat better error handling?