Grid OSL shader

Hi, I’m trying to have a grid shader on my scene but the problem is that the coordinates doesn’t match in the borders, please check the attached blend file:

W_grid.blend (454 KB)

You can see how the borders are offset, I would like to have a shader that always has the correct coordinates but I can still being able to adjust the scale, any idea how to achieve this?

Thanks in advance.