added sanity checks to the packet handling