Improve performance by avoiding digest except when necessary