bug fix for error handling at end of packet