Fix grid ref calculation