add support for irregular grids, this may need some debugging