add error handling for malformed packets