fix crash caused by empty packets and add more checks -- review request #44