clean up and optimize reply_digest (bug #4447)