4 digit 7 segment display

Hey everyone!
I have kept the previous problem aside just for the time being. My new goal is to display 4 digit numbers on the 7 segment display. I will be giving the numbers in the program itself, not serially. So i came up with a code, which is of course is not optimum, but one thing very peculiar that I noticed was that whenever there is a digit 5 in the number that I give that digit displaying 5 becomes brighter than the rest. Be it in the units, or tens or hundreds or thousands. Whats worse is that when I gave 5555 the display started flickering. Nothing like this happens with any other digit and when there are any other digits, everything is evenly bright and there is no flickering. I will attach my code below. please bear with my sloppiness.

int latchPin = 2; //pin 12 on the 595
int dataPin = 3; //pin 14 on the 595
int clockPin = 4; //pin 11 on the 595
int shift = 256;
int number = 8444;
int units;
int tens;
int hundreds;
int thousands;
int x;
int y;
void setup()
{
  Serial.begin(9600);
  pinMode(latchPin, OUTPUT);
  pinMode(dataPin, OUTPUT);
  pinMode(clockPin, OUTPUT);
}

void loop()
{

  if (number > 9 && number < 100)
  {
    units = number % 10;
    tens = number / 10;
  }
  else if ( number > 99 && number < 1000)
  {
    units = number % 10;
    x = number / 10;
    tens = x % 10;
    hundreds = x / 10;
  }
  else if ( number > 999 && number < 10000)
  {
    units = number % 10;
    x = number / 10;
    tens = x % 10;
    y = x / 10;
    hundreds = y % 10;
    thousands = y / 10;
  }
  else
  {
    digitalWrite(latchPin, LOW);
    shiftOut(dataPin, clockPin, MSBFIRST, shift * 8  >> 8 );
    shiftOut(dataPin, clockPin, MSBFIRST, shift * 8 + 64 );
    digitalWrite(latchPin, HIGH);
  }

  switch (units)
  {
    case 0:
      //0
      digitalWrite(latchPin, LOW);
      shiftOut(dataPin, clockPin, MSBFIRST, shift * 8  >> 8 );
      shiftOut(dataPin, clockPin, MSBFIRST, shift * 8 + 64 );
      digitalWrite(latchPin, HIGH);
      //delay(500);
      break;
    case 1:
      //1
      digitalWrite(latchPin, LOW);
      shiftOut(dataPin, clockPin, MSBFIRST, shift * 8  >> 8 );
      shiftOut(dataPin, clockPin, MSBFIRST, shift * 8 + 121);
      digitalWrite(latchPin, HIGH);
      //delay(500);
      break;
    case 2:
      //2
      digitalWrite(latchPin, LOW);
      shiftOut(dataPin, clockPin, MSBFIRST, shift * 8  >> 8 );
      shiftOut(dataPin, clockPin, MSBFIRST, shift * 8 + 36);
      digitalWrite(latchPin, HIGH);
      //delay(500);
      break;
    case 3:
      //3
      digitalWrite(latchPin, LOW);
      shiftOut(dataPin, clockPin, MSBFIRST, shift * 8 >> 8 );
      shiftOut(dataPin, clockPin, MSBFIRST, shift * 8 + 48);
      digitalWrite(latchPin, HIGH);
      //delay(500);
      break;
    case 4:
      //4
      digitalWrite(latchPin, LOW);
      shiftOut(dataPin, clockPin, MSBFIRST, shift * 8 >> 8 );
      shiftOut(dataPin, clockPin, MSBFIRST, shift * 8 + 25);
      digitalWrite(latchPin, HIGH);
      //delay(500);
      break;
    case 5:
      //5
      digitalWrite(latchPin, LOW);
      shiftOut(dataPin, clockPin, MSBFIRST, shift * 8   >> 8 );
      shiftOut(dataPin, clockPin, MSBFIRST, shift * 8 + 18);
      digitalWrite(latchPin, HIGH);
      Serial.println("5 is printed");
      //delay(500);
      break;
    case 6:
      //6
      digitalWrite(latchPin, LOW);
      shiftOut(dataPin, clockPin, MSBFIRST, shift * 8   >> 8 );
      shiftOut(dataPin, clockPin, MSBFIRST, shift * 8 + 2);
      digitalWrite(latchPin, HIGH);
      //delay(500);
      break;
    case 7:
      //7
      digitalWrite(latchPin, LOW);
      shiftOut(dataPin, clockPin, MSBFIRST, shift * 8  >> 8 );
      shiftOut(dataPin, clockPin, MSBFIRST, shift * 8 + 120);
      digitalWrite(latchPin, HIGH);
      //delay(500);
      break;
    case 8:
      //8
      digitalWrite(latchPin, LOW);
      shiftOut(dataPin, clockPin, MSBFIRST, shift * 8  >> 8 );
      shiftOut(dataPin, clockPin, MSBFIRST, shift * 8 + 0);
      digitalWrite(latchPin, HIGH);
      //delay(500);
      break;
    case 9:
      //9
      digitalWrite(latchPin, LOW);
      shiftOut(dataPin, clockPin, MSBFIRST, shift * 8  >> 8 );
      shiftOut(dataPin, clockPin, MSBFIRST, shift * 8 + 16);
      digitalWrite(latchPin, HIGH);
      //delay(500);
      break;
  }
  delay(1);

    switch (tens)
  {
    case 0:
      //0
      digitalWrite(latchPin, LOW);
      shiftOut(dataPin, clockPin, MSBFIRST, shift * 4  >> 8 );
      shiftOut(dataPin, clockPin, MSBFIRST, shift * 4 + 64 );
      digitalWrite(latchPin, HIGH);
      //delay(500);
      break;
    case 1:
      //1
      digitalWrite(latchPin, LOW);
      shiftOut(dataPin, clockPin, MSBFIRST, shift * 4   >> 8 );
      shiftOut(dataPin, clockPin, MSBFIRST, shift * 4 + 121);
      digitalWrite(latchPin, HIGH);
      //delay(500);
      break;
    case 2:
      //2
      digitalWrite(latchPin, LOW);
      shiftOut(dataPin, clockPin, MSBFIRST, shift * 4   >> 8 );
      shiftOut(dataPin, clockPin, MSBFIRST, shift * 4 + 36);
      digitalWrite(latchPin, HIGH);
      //delay(500);
      break;
    case 3:
      //3
      digitalWrite(latchPin, LOW);
      shiftOut(dataPin, clockPin, MSBFIRST, shift * 4   >> 8 );
      shiftOut(dataPin, clockPin, MSBFIRST, shift * 4 + 48);
      digitalWrite(latchPin, HIGH);
      //delay(500);
      break;
    case 4:
      //4
      digitalWrite(latchPin, LOW);
      shiftOut(dataPin, clockPin, MSBFIRST, shift * 4 >> 8 );
      shiftOut(dataPin, clockPin, MSBFIRST, shift * 4 + 25);
      digitalWrite(latchPin, HIGH);
      //delay(500);
      break;
    case 5:
      //5
      digitalWrite(latchPin, LOW);
      shiftOut(dataPin, clockPin, MSBFIRST, shift * 4   >> 8 );
      shiftOut(dataPin, clockPin, MSBFIRST, shift * 4 + 18);
      digitalWrite(latchPin, HIGH);
      Serial.println("5 is printed");
      //delay(500);
      break;
    case 6:
      //6
      digitalWrite(latchPin, LOW);
      shiftOut(dataPin, clockPin, MSBFIRST, shift * 4   >> 8 );
      shiftOut(dataPin, clockPin, MSBFIRST, shift * 4 + 2);
      digitalWrite(latchPin, HIGH);
      //delay(500);
      break;
    case 7:
      //7
      digitalWrite(latchPin, LOW);
      shiftOut(dataPin, clockPin, MSBFIRST, shift * 4   >> 8 );
      shiftOut(dataPin, clockPin, MSBFIRST, shift * 4 + 120);
      digitalWrite(latchPin, HIGH);
      //delay(500);
      break;
    case 8:
      //8
      digitalWrite(latchPin, LOW);
      shiftOut(dataPin, clockPin, MSBFIRST, shift * 4  >> 8 );
      shiftOut(dataPin, clockPin, MSBFIRST, shift * 4 + 0);
      digitalWrite(latchPin, HIGH);
      //delay(500);
      break;
    case 9:
      //9
      digitalWrite(latchPin, LOW);
      shiftOut(dataPin, clockPin, MSBFIRST, shift * 4  >> 8 );
      shiftOut(dataPin, clockPin, MSBFIRST, shift * 4 + 16);
      digitalWrite(latchPin, HIGH);
      //delay(500);
      break;
  }
  delay(1);

I have included only the code for 2 digits but the hundreds and thousands code is also similar.