added logic for bad checksum and length mismatch