2nd version of grain perimeter