Index: lab4/lab4.c
===================================================================
--- lab4/lab4.c	(revision 86)
+++ lab4/lab4.c	(revision 87)
@@ -44,12 +44,14 @@
     uint8_t mouse_irq_bit = 12;
     int mouse_id = 0;
     int mouse_irq = BIT(mouse_irq_bit);
-    if ((ret = mouse_set_data_report(true))) return ret;
-    //if ((ret = mouse_enable_data_reporting())) return ret;
 
-    if (subscribe_mouse_interrupt(mouse_irq_bit, &mouse_id)) return 1;
+    if (subscribe_mouse_interrupt(mouse_irq_bit, &mouse_id)) return 1; // subscribes mouse interrupts in exclusive mode
+    if (sys_irqdisable(&mouse_id)) return 1; // temporarily disables our interrupts notifications
+    if ((ret = mouse_set_data_report(true))) return ret; // enables mouse data reporting
+    if (sys_irqenable(&mouse_id)) return 1; // re-enables our interrupts notifications
+
     /// cycle
-    int good = cnt != 0;
+    int good = (cnt != 0);
     uint32_t cnt_now = 0;
     while (good) {
         /* Get a request message. */
@@ -77,8 +79,10 @@
             /* no standart message expected: do nothing */
         }
     }
-    if (unsubscribe_interrupt(&mouse_id)) return 1;
-    if (mouse_set_data_report(false)) return 1;
+    if (sys_irqdisable(&mouse_id)) return 1; // temporarily disables our interrupts notifications
+    if (mouse_set_data_report(false)) return 1; // enables mouse data reporting
+    if (sys_irqenable(&mouse_id)) return 1; // re-enables our interrupts notifications
+    if (unsubscribe_interrupt(&mouse_id)) return 1; // unsubscribes interrupts
     return 0;
 }
 
@@ -93,25 +97,6 @@
         mouse_print_packet(&pp);
         tickdelay(micros_to_ticks(period*1000));
     }
-    /*
-    while (good) {
-
-        if ((ret = mouse_read_data(&data))) return ret;
-
-        if ((data & FIRST_BYTE_ID) || sz) {
-            packet[sz] = data;
-            sz++;
-        }
-        if (sz == 3) {
-            struct packet pp = mouse_parse_packet(packet);
-            mouse_print_packet(&pp);
-            packetCounter++;
-            sz = 0;
-            if (packetCounter == cnt) good = 0;
-        }
-        tickdelay(micros_to_ticks(period*1e3));
-    }
-    */
     // Set Stream mode
     if ((ret = mouse_issue_cmd(SET_STREAM_MD))) return ret;
     // Disable data reporting
@@ -139,9 +124,12 @@
     uint8_t mouse_irq_bit = 12;
     int mouse_id = 0;
     int mouse_irq = BIT(mouse_irq_bit);
-    if (mouse_set_data_report(true)) return 1;
 
-    if (subscribe_mouse_interrupt(mouse_irq_bit, &mouse_id)) return 1;
+    if (subscribe_mouse_interrupt(mouse_irq_bit, &mouse_id)) return 1; // subscribes mouse interrupts in exclusive mode
+    if (sys_irqdisable(&mouse_id)) return 1; // temporarily disables our interrupts notifications
+    if (mouse_set_data_report(true)) return 1; // enables mouse data reporting
+    if (sys_irqenable(&mouse_id)) return 1; // re-enables our interrupts notifications
+
     /// cycle
     int good = 1;
     while (good) {
@@ -176,8 +164,10 @@
         }
     }
 
-    if (unsubscribe_interrupt(&mouse_id)) return 1;
-    if (mouse_set_data_report(false)) return 1;
+    if (sys_irqdisable(&mouse_id)) return 1; // temporarily disables our interrupts notifications
+    if (mouse_set_data_report(false)) return 1; // enables mouse data reporting
+    if (sys_irqenable(&mouse_id)) return 1; // re-enables our interrupts notifications
+    if (unsubscribe_interrupt(&mouse_id)) return 1; // unsubscribes interrupts
 
     if (unsubscribe_interrupt(&timer_id)) return 1;
 
@@ -193,9 +183,12 @@
     uint8_t mouse_irq_bit = 12;
     int mouse_id = 0;
     int mouse_irq = BIT(mouse_irq_bit);
-    if ((ret = mouse_set_data_report(true))) return ret;
 
-    if (subscribe_mouse_interrupt(mouse_irq_bit, &mouse_id)) return 1;
+    if (subscribe_mouse_interrupt(mouse_irq_bit, &mouse_id)) return 1; // subscribes mouse interrupts in exclusive mode
+    if (sys_irqdisable(&mouse_id)) return 1; // temporarily disables our interrupts notifications
+    if ((ret = mouse_set_data_report(true))) return ret; // enables mouse data reporting
+    if (sys_irqenable(&mouse_id)) return 1; // re-enables our interrupts notifications
+
     /// cycle
     int good = 1;
 
@@ -235,8 +228,11 @@
             /* no standart message expected: do nothing */
         }
     }
-    if (unsubscribe_interrupt(&mouse_id)) return 1;
-    if (mouse_set_data_report(false)) return 1;
 
+    if (sys_irqdisable(&mouse_id)) return 1; // temporarily disables our interrupts notifications
+    if (mouse_set_data_report(false)) return 1; // enables mouse data reporting
+    if (sys_irqenable(&mouse_id)) return 1; // re-enables our interrupts notifications
+    if (unsubscribe_interrupt(&mouse_id)) return 1; // unsubscribes interrupts
+
     return 0;
 }
Index: lab4/mouse.c
===================================================================
--- lab4/mouse.c	(revision 86)
+++ lab4/mouse.c	(revision 87)
@@ -91,7 +91,7 @@
     for (unsigned int i = 0; i < KBC_NUM_TRIES; i++) {
         if ((ret = kbc_issue_cmd(MOUSE_WRITE_B))) return ret;
         if ((ret = kbc_issue_arg(cmd))) return ret;
-        if ((ret = mouse_read_ack(&ack))) return ret;
+        if ((ret = mouse_read_byte(&ack))) return ret;
 
         if (ack == ACK_OK) return SUCCESS;
         if (ack == ACK_ERROR) return INVALID_COMMAND;
@@ -115,21 +115,6 @@
     return TIMEOUT_ERROR;
 }
 
-int (mouse_read_ack)(uint8_t *byte) {
-    int ret = 0;
-    uint8_t stat;
-    //for(int i = 0; i < KBC_NUM_TRIES; ++i){
-        if((ret = util_sys_inb(STATUS_REG, &stat))) return ret;
-        //if((stat&OUT_BUF_FUL) && (stat&AUX_MOUSE)) {
-            if(stat & (PARITY_ERROR | TIME_OUT_REC)) return OTHER_ERROR;
-            if((ret = util_sys_inb(OUTPUT_BUF, byte))) return ret;
-            else return SUCCESS;
-        //}
-        //tickdelay(micros_to_ticks(DELAY));
-    //}
-    //return TIMEOUT_ERROR;
-}
-
 int (mouse_poll_byte)(uint8_t *byte, uint16_t period) {
     int ret = 0;
     uint8_t stat;
Index: lab4/mouse.h
===================================================================
--- lab4/mouse.h	(revision 86)
+++ lab4/mouse.h	(revision 87)
@@ -73,14 +73,6 @@
 int (mouse_read_byte)(uint8_t *byte);
 
 /**
- * @brief Same as @ref mouse_read_byte, except it does not wait for output buffer
- * to be full, since ACK is considered to arrive instantaneously somehow.
- * @param   byte    pointer to byte where ACK will be stored
- * @return ERROR_CODE code representing the result of the operation, SUCCESS code is returned if everything is OK
- */
-int (mouse_read_ack)(uint8_t *byte);
-
-/**
  * @brief Polls OUT_BUF for byte coming from mouse.
  * @param   byte    pointer to byte read from OUT_BUF
  * @param   period  time (in milliseconds) the poller should wait between pollings of bytes
Index: lab4/state_machine.c
===================================================================
--- lab4/state_machine.c	(revision 86)
+++ lab4/state_machine.c	(revision 87)
@@ -71,6 +71,7 @@
 
     if (event == NULL)
         return response;
+
     switch (state) {
         case INITIAL:
             if (event->type == LB_PRESSED)
@@ -78,7 +79,7 @@
             break;
         case DRAG_UP:
             if (event->type == MOUSE_MOV) {
-                if (abs(event->delta_x) > tolerance || abs(event->delta_y) > tolerance) {
+                if (event->delta_x < -tolerance || event->delta_y < -tolerance) {
                     state = INITIAL;
                     x_length = 0;
                     y_length = 0;
@@ -124,7 +125,7 @@
             break;
         case DRAG_DOWN:
             if (event->type == MOUSE_MOV) {
-                if (abs(event->delta_x) > tolerance || abs(event->delta_y) > tolerance) {
+                if (event->delta_x < -tolerance || event->delta_y > tolerance) {
                     state = INITIAL;
                     x_length = 0;
                     y_length = 0;
