     {0,  'z',  '%'}, //B10101
     {0,  'y',  '?'}, //B10110
     {0,  'x',  'x'}, //B10111
-    {0,  'i',  '2'}, //B11000
+    {KEY_LEFT_CTRL ,  'i',  '2'}, //B11000
     {0,  'l',  '£'}, //B11001
-    {0,  'r',  ';'}, //B11010
+    {0 /* win */,  'r',  ';'}, //B11010
     {0,  'w',  ':'}, //B11011
-    {0,  'd',  '3'}, //B11100
+    {0 /* alt */,  'd',  '3'}, //B11100
     {0, '\'',  '&'}, //B11101
-    {0,  'f',  '4'}, //B11110
+    {0 /* clear state */,  'f',  '4'}, //B11110
     {0,  'p',  '5'}  //B11111
 };
+
+#define TOGGLE_COUNT 24
+bool toggles[TOGGLE_COUNT] = {};
+
+char prevInput = 0;
+char prevCharacter = 0;
 
 char currentLayer = ALPHA_LAYER;
 bool commandClear = true;

  }
}

char prevCharacter = 0;

void loop() {
  char firstRead = readButtons();
  delay(25);
  char secondRead = readButtons();
  if (firstRead == secondRead) {
    char character = decodeInput(firstRead);
    if (character != prevCharacter) {
      Keyboard.release(prevCharacter);
      prevCharacter = character;
      if (character != 0) {

  return (~(PINB >> 1)) & B00111111;
}

void toggleKey(char key) {
  if (!toggles[key >> 7]) {
    toggles[key >> 7] = true;
    Keyboard.press(key);
  } else {
    toggles[key >> 7] = false;
    Keyboard.release(key);
  }
}

void resetState() {
  Keyboard.releaseAll();
  currentLayer = ALPHA_LAYER;
  for(char i = 0; i < TOGGLE_COUNT; ++i) {
    toggles[i] = false;
  }
}

char decodeInput(char input) {
  if (input & 1) {
    switch(input){
      case B000001:
        toggleKey(KEY_LEFT_SHIFT);
        return 0;
      case B111101:
        resetState();
        return 0;
      case B100001:
        toggleKey(KEY_LEFT_CTRL);
        return 0;
      case B110001:
        toggleKey(KEY_LEFT_GUI);
        return 0;
      case B111001:
        toggleKey(KEY_LEFT_ALT);
        return 0;
      case B001101:
        currentLayer = NUMERIC_LAYER;
        return 0;
    }
    commandClear = false;
    return layers[input >> 1][CMD_LAYER];
