Improve performance of x,y coordinate search algorithm in grid module