refactored search for adjacent squares on grid