         DEBUG_PRINT("[INIT] Sending IR: ");
         DEBUG_PRINTLN(session_id);
         irsend.sendSony(session_id, 16);
-        m = XBeeMode;
+        XBeeReturnCount = 0;
+        start_time = millis();
+        m = WaitMode;
         XBee.begin(9600);
-        // TODO
-        // better wait for a while before ending XBee session
-        //
       }
       else {
         XBee.begin(9600);

int ledPin = 8;

struct XBeePacket XBeePacketArr[20];
char message[50];
enum mode {
  BTMode,
  XBeeMode
};
mode m;

void setup()
{

  BT.begin(57600);
  delay(300);
  m = BTMode;
  XBeeReturnCount = 0;
  Serial.print("system begins");
}

