Optimize next square search through caching the next square.