added another for loop to fix the up conditional, this loop checks ll previous cells