multiple optimisations to grid calculation and neighbour location