Index: lab3/kbc.c
===================================================================
--- lab3/kbc.c	(revision 60)
+++ lab3/kbc.c	(revision 61)
@@ -43,6 +43,19 @@
     return 1;
 }
 
+int (kbc_issue_arg)(uint8_t arg){
+    uint8_t stat;
+    for(int i = 0; i < KBC_NUM_TRIES; ++i){
+        if(util_sys_inb(STATUS_REG, &stat)) return 1;
+        if((stat&IN_BUF_FULL) == 0){
+            if(sys_outb(KBC_CMD_ARG, arg)) return 1;
+            return 0;
+        }
+        tickdelay(micros_to_ticks(DELAY));
+    }
+    return 1;
+}
+
 int (kbc_read_byte)(uint8_t *byte){
     uint8_t stat;
     while(true){
Index: lab3/kbc.h
===================================================================
--- lab3/kbc.h	(revision 60)
+++ lab3/kbc.h	(revision 61)
@@ -45,6 +45,13 @@
 int (kbc_issue_cmd)(uint8_t cmd);
 
 /**
+ * @brief Low-level function to issue an argument of a command
+ * @param cmd argument to be issued
+ * @return 0 if operation was successful, 1 otherwise
+ */
+int (kbc_issue_arg)(uint8_t arg);
+
+/**
  * @brief Low-level function for reading byte from keyboard
  * Low-level function for reading byte from keyboard. Waits until output buffer
  * is full
Index: lab3/keyboard.c
===================================================================
--- lab3/keyboard.c	(revision 60)
+++ lab3/keyboard.c	(revision 61)
@@ -12,38 +12,34 @@
     return (sys_irqsetpolicy(KBC_IRQ, IRQ_REENABLE | IRQ_EXCLUSIVE, interrupt_id));
 }
 
+int done = 1;
+int sz = 1;
 int got_error_keyboard = 0;
-int two_byte_scancode = 0;
 
 void (kbc_ih)(void) {
+    if(done) sz = 1;
+    else     sz++;
     uint8_t status = 0;
     got_error_keyboard = 0;
-
     if (util_sys_inb(STATUS_REG, &status)) {
         got_error_keyboard = 1;
         return;
     }
-
     if (status & (TIME_OUT_REC | PARITY_ERROR)) {
         got_error_keyboard = 1;
         return;
     }
-
+    if ((status & OUT_BUF_FUL) == 0 || (status & AUX_MOUSE) != 0) {
+        got_error_keyboard = 1;
+        return;
+    }
     uint8_t byte = 0;
-
     if (util_sys_inb(OUTPUT_BUF, &byte)) {
         got_error_keyboard = 1;
         return;
     }
-
-    if (two_byte_scancode) {
-        scancode[1] = byte;
-        two_byte_scancode = 0;
-    } else {
-        scancode[0] = byte;
-        two_byte_scancode = (byte == TWO_BYTE_CODE);
-    }
-
+    scancode[sz-1] = byte;
+    done = !(TWO_BYTE_CODE == byte);
 }
 
 int (keyboard_poll)(uint8_t bytes[], uint8_t *size){
Index: lab3/keyboard.h
===================================================================
--- lab3/keyboard.h	(revision 60)
+++ lab3/keyboard.h	(revision 61)
@@ -14,7 +14,8 @@
 int (subscribe_keyboard_interrupt)(uint8_t interrupt_bit, int *interrupt_id);
 
 uint8_t scancode[2];
-int two_byte_scancode;
+int done;
+int sz;
 int got_error_keyboard;
 
 /**
Index: lab3/lab3.c
===================================================================
--- lab3/lab3.c	(revision 60)
+++ lab3/lab3.c	(revision 61)
@@ -56,10 +56,6 @@
                 case HARDWARE: /* hardware interrupt notification */
                     if (msg.m_notify.interrupts & kbc_irq) { /* subscribed interrupt */
                         kbc_ih();
-                        if (!(two_byte_scancode || got_error_keyboard)) { /* finished processing a scancode */
-                            if (scancode[0] == TWO_BYTE_CODE) kbd_print_scancode(!(scancode[1] & BREAK_CODE_BIT), 2, scancode);
-                            else                              kbd_print_scancode(!(scancode[0] & BREAK_CODE_BIT), 1, scancode);
-                        } else { break; }
                         if(done)
                             kbd_print_scancode(!(scancode[sz-1] & BREAK_CODE_BIT), sz, scancode);
                         if (scancode[0] == ESC_BREAK_CODE) good = 0;
@@ -131,10 +127,6 @@
                     }
                     if (msg.m_notify.interrupts & kbc_irq) { /// subscribed interrupt
                         kbc_ih();
-
-                        if (!(two_byte_scancode || got_error_keyboard)) { /// finished processing a scancode
-                            if (scancode[0] == TWO_BYTE_CODE) kbd_print_scancode(!(scancode[1] & BREAK_CODE_BIT), 2, scancode);
-                            else                              kbd_print_scancode(!(scancode[0] & BREAK_CODE_BIT), 1, scancode);
                         if(done) {
                             kbd_print_scancode(!(scancode[sz-1] & BREAK_CODE_BIT), sz, scancode);
                             time = 0;
