improved grid graph algorithms