setLocked was not declared in this scope HELP PLEASE--- THe code is for keypad

#include <Keypad.h>

char* secretCode = "6669";
int position =  0;

const byte ROWS = 4; // Four rows

const byte COLS = 3; // Three columns

// Define the Keymap

char keys[ROWS][COLS] = { {'1', '2', '3'}, {'4', '5', '6'}, {'7', '8', '9'}, {'#', '0', '*'} };

// Connect keypad ROW0, ROW1, ROW2 and ROW3 to these Arduino pins.

byte rowPins[ROWS] = { 2, 7, 6, 4 };

// Connect keypad COL0, COL1 and COL2 to these Arduino pins.

byte colPins[COLS] = { 3, 1, 5 };

Keypad keypad = Keypad( makeKeymap(keys), rowPins, colPins, ROWS, COLS );

int redPin = 9;
int greenPin = 8;

void setup()
{
  pinMode (redPin, OUTPUT);
  pinMode (greenPin, OUTPUT);
  setLocked(true);
}

void loop() {
  char key = keypad.getKey();
  if (Key == '*' || Key == '#')
  {
    position = 0;
    setLocked(true);
  }

  {
    if  (Key == secretCode [position])
    }
  position ++;
  {
    if (position == 4)
    {

      setLocked(false);
    }
    delay(100);

  }

  void setLocked(int locked)
  {
    if (locked)
    {
      digitalWrite(redPin, HIGH);
      digitalWrite(greenPin, LOW);
    }

    else
      digitalWrite(redPin, LOW);
    digitalWrite(greenPin, HIGH);
  }
}

Take a close look at all of the { and all the }