Add comments and more checks to the digest_dynamic function.