might be nice to pull out this check into a utility function.