Pulled common code into utility function.