Corrected handling of grid ids.