This logic could be extracted to a helper.