 
 void loop() {
   delay (100);
+  if (!GM_DEBUG) {
+  serial_process_command();
+  }
 }
 
-void process_command (int num_command) {
-  byte cmd_buffer;
+void serial_process_command() {
+  if (Serial.available()) {
+	  byte cmd_buffer = Serial.read();
+	  execute_command(cmd_buffer);
+	} 
 
-  while (Wire.available()) {
-  
-    cmd_buffer = Wire.read();
-    
+}
+
+void execute_command(byte cmd_buffer) {
     if (!state.ready) {
       if (read_command (cmd_buffer, GM_CMD_READY)) {
 	      state.ready = true;
 	      update_machine();
       }
-      continue;
+      return;
     }
 
     if (GM_DEBUG) {

    
    // execute current state
    update_machine();      
  }
}


    Serial.println (state);
  }
  digitalWrite (pin, state ? HIGH : LOW);
}
