   bool anyPressed = false;
   bool changed = false;
   for( int i=0; i<buttonsAllocated; i++ ) {
-    bool lastState = getButton(buttonCode[i]);
+    bool lastState = buttonLastState[i];
     bool buttonPressed = checkButton(i);
     if( lastState != buttonPressed) {
-      setButton(buttonCode[i], buttonPressed);
+      buttonLastState[i] = buttonPressed;
       changed = true;
     }
     anyPressed |= buttonPressed;

#include <ESP8266WiFi.h>
#include <WiFiUdp.h>

const char* ssid     = "tulix-upstairs";
const char* password = "vivalasalsa07";

const char* DESTINATION_HOST = "ulno-work";
//const char* DESTINATION_HOST = "localhost";
//const char* DESTINATION_HOST = "192.168.15.194";
int DESTINATION_PORT = 19877;

const int NUMBER_OF_BUTTONS = 256;
const int NUMBER_OF_BUTTON_BYTES = (NUMBER_OF_BUTTONS + 7)/8;
const int NUMBER_OF_AXIS = 16;
const int NUMBER_OF_AXIS_BYTES = NUMBER_OF_AXIS * 2;
byte message[NUMBER_OF_BUTTON_BYTES + NUMBER_OF_AXIS_BYTES];
const int MAX_NUMBER_OF_BUTTONS = 16;
const int BUTTON_THRES = 16; // how many times has an on be counted to assume this button is on
//const int STATUS_LED = 2;

  }
}

   
bool checkButton( int buttonIndex ) {
    if(digitalRead( buttonPin[buttonIndex] ) == (buttonPullup[buttonIndex]?LOW:HIGH)) {
        if(buttonThresCounter[buttonIndex] < BUTTON_THRES)
