Export the logic to a helper function.