Added basic error checking and tampering checks.