Pulled out a helper function.