small could pull this logic to a helper function