Can't figure how to debounce this

Thank you both.

This is my try

const int pLatch = 7;  
const int pClock = 6;  
const int pData  = 5;  

static const int num_buttons = 8;

int last_debounce_time[8] = { 0, 0, 0, 0, 0, 0, 0, 0 };
int debounce_delay = 500;
int buttons_state[8];
int buttons_last_state[8] =  { LOW, LOW, LOW, LOW, LOW, LOW, LOW, LOW };


void setup()
{
  Serial.begin(115200);
  pinMode (pLatch, OUTPUT);
  pinMode (pClock, OUTPUT);
  pinMode (pData, INPUT); 

  digitalWrite(pClock, LOW);  
  digitalWrite(pLatch, HIGH); 
}

void loop()
{
  digitalWrite(pLatch, LOW);  
  delayMicroseconds(5);
  digitalWrite(pLatch, HIGH);  
  
  for(int i = 0;i<num_buttons;i++)
  {
    int reading = digitalRead(pData); 
      
    // If the switch changed, due to noise or pressing:    
    if(reading != buttons_last_state[i])
    {
      last_debounce_time[i] = millis();
    }
      
    if ((millis() - last_debounce_time[i]) > debounce_delay) 
    {
      // whatever the reading is at, it's been there for longer
      // than the debounce delay, so take it as the actual current state:

      // if the button state has changed:
      if(reading != buttons_state[i])
      {
        buttons_state[i] = reading;     
      }      
    }       
   
    buttons_last_state[i] = reading;
   
    digitalWrite(pClock, HIGH);  
    delayMicroseconds(5);
    digitalWrite(pClock, LOW);    

  }

  for(int i = 0;i<num_buttons;i++)
  {
    Serial.print(buttons_state[i]);
  }
  Serial.println("");
  delay(1);
}

It doesn't work...
I print the byte after each cycle, so at the start I get 00000000, so far so good, then I turn on the 2 buttons I have attached to the A and B pins and I get 00000011...still ok, but then I turn off both buttons and nothing changes (still getting 00000011), and after a few seconds I start getting noise in those two bits.

I can't figure what's wrong.