Index: trunk/code/projects/colonet/ColonetServer/Command.cpp
===================================================================
--- trunk/code/projects/colonet/ColonetServer/Command.cpp	(revision 417)
+++ trunk/code/projects/colonet/ColonetServer/Command.cpp	(revision 418)
@@ -174,8 +174,8 @@
           int_tokens[0], int_tokens[1], int_tokens[2]);
   if (colonet_wl_send((short)pool_index, int_tokens[0], (ColonetMessageType)int_tokens[1], int_tokens[2], arguments)
       != 0) {
-    fprintf(stderr, "Error - Colonet_wl_send failed.");
-    return -1;
+    fprintf(stderr, "Error - Colonet_wl_send failed.\n");
+    exit(1);
   }
 
   return 0;
@@ -266,6 +266,17 @@
   int num_robots;
   int* xbee_ids = colonet_get_xbee_ids(&num_robots);
 
+
+
+  printf("num_robots: %d\n", num_robots);
+  printf("xbee_ids: ");
+  for (int i = 0; i < num_robots; i++) {
+    printf("%d ", xbee_ids[i]);
+  }
+  printf("\n");
+
+
+
   if (!connection_pool) {
     return -1;
   }
Index: trunk/code/projects/colonet/ColonetServer/colonet_wireless.cpp
===================================================================
--- trunk/code/projects/colonet/ColonetServer/colonet_wireless.cpp	(revision 417)
+++ trunk/code/projects/colonet/ColonetServer/colonet_wireless.cpp	(revision 418)
@@ -113,8 +113,10 @@
     }
   } else {
     printf("sending to specific robot.\n");
-    wl_send_robot_to_robot_global_packet(COLONET_PACKET_GROUP_ID, (char)msg_type, (char*)(&pkt),
-                                         sizeof(ColonetRobotServerPacket), dest, COLONET_RESPONSE_PACKET_FRAME_ID);
+    if (wl_send_robot_to_robot_global_packet(COLONET_PACKET_GROUP_ID, (char)msg_type, (char*)(&pkt),
+      sizeof(ColonetRobotServerPacket), dest, COLONET_RESPONSE_PACKET_FRAME_ID) != 0) {
+      return -1;
+    }
   }
 
   return 0;
@@ -130,10 +132,10 @@
 
   wl_token_iterator_begin();
 
-  int* p = ids;
+  int i = 0;
   while (wl_token_iterator_has_next()) {
-    *p = wl_token_iterator_next();
-    p++;
+    ids[i] = wl_token_iterator_next();
+    i++;
   }
 
   *numrobots = num_robots;
@@ -164,7 +166,7 @@
 /**************************** Private functions ******************************/
 
 static void timeout_handler() {
-  printf("colonet wireless - timeout!\n");
+  // printf("colonet wireless - timeout!\n");
 }
 
 static void handle_response(int frame, int received) {
Index: trunk/code/projects/colonet/ColonetServer/ColonetServer.cpp
===================================================================
--- trunk/code/projects/colonet/ColonetServer/ColonetServer.cpp	(revision 417)
+++ trunk/code/projects/colonet/ColonetServer/ColonetServer.cpp	(revision 418)
@@ -30,7 +30,7 @@
 
 #define u_int32_t unsigned
 
-static ConnectionPool * connection_pool;
+static ConnectionPool* connection_pool;
 
 /**
  * @brief Default constructor for ColonetServer
Index: trunk/code/projects/colonet/ColonetServer/Makefile
===================================================================
--- trunk/code/projects/colonet/ColonetServer/Makefile	(revision 417)
+++ trunk/code/projects/colonet/ColonetServer/Makefile	(revision 418)
@@ -28,9 +28,10 @@
 	make; ./ColonetServer
 	../vision/vision.sh
 
-ColonetServer: $(COLONETCPPFILES) $(COLONETFILES) $(LOGGINGFILES)
+../../libwireless/lib/libwireless_colonet.a: ../../libwireless/lib/*.c ../../libwireless/lib/*.h
 	cd ../../libwireless/lib; make colonet
 
+ColonetServer: ../../libwireless/lib/libwireless_colonet.a $(COLONETCPPFILES) $(COLONETFILES) $(LOGGINGFILES)
 	@echo "---begin compilation---"
 	@echo ""
 	@echo "---create object files---"
Index: trunk/code/projects/libwireless/lib/wl_token_ring.c
===================================================================
--- trunk/code/projects/libwireless/lib/wl_token_ring.c	(revision 417)
+++ trunk/code/projects/libwireless/lib/wl_token_ring.c	(revision 418)
@@ -64,70 +64,69 @@
 /*Function Prototypes*/
 
 /*Wireless Library Prototypes*/
-void wl_token_ring_timeout_handler(void);
-void wl_token_ring_response_handler(int frame, int received);
-void wl_token_ring_receive_handler(char type, int source, unsigned char* packet,
-							int length);
-void wl_token_ring_cleanup(void);
+static void wl_token_ring_timeout_handler(void);
+static void wl_token_ring_response_handler(int frame, int received);
+static void wl_token_ring_receive_handler(char type, int source, unsigned char* packet, int length);
+static void wl_token_ring_cleanup(void);
 
 /*Helper Functions*/
-void wl_token_pass_token(void);
-int get_token_distance(int robot1, int robot2);
-void wl_token_get_token(void);
+static void wl_token_pass_token(void);
+static int get_token_distance(int robot1, int robot2);
+static void wl_token_get_token(void);
 
 /*Packet Handling Routines*/
-void wl_token_pass_receive(int source, char nextRobot, unsigned char* sensorData, int sensorDataLength);
-void wl_token_bom_on_receive(int source);
-void wl_token_join_receive(int source);
-void wl_token_join_accept_receive(int source);
+static void wl_token_pass_receive(int source, char nextRobot, unsigned char* sensorData, int sensorDataLength);
+static void wl_token_bom_on_receive(int source);
+static void wl_token_join_receive(int source);
+static void wl_token_join_accept_receive(int source);
 
 /*Global Variables*/
 
 //the sensor matrix
-SensorMatrix* sensorMatrix;
+static SensorMatrix* sensorMatrix;
 
 //the robot we are waiting to say it has received the token. -1 if unspecified
-int wl_token_next_robot = -1;
+static int wl_token_next_robot = -1;
 
 //true if the robot should be in the token ring, 0 otherwise
-int ringState = NONMEMBER;
+static int ringState = NONMEMBER;
 //the id of the robot who accepted us into the token ring, only used in ACCEPTED state
-int acceptor = -1;
+static int acceptor = -1;
 //id of the robot we are accepting
-int accepted = -1;
+static int accepted = -1;
 
 //the counter for when we assume a robot is dead
-int deathDelay = -1;
+static int deathDelay = -1;
 //the counter for joining, before we form our own token ring
-int joinDelay = -1;
+static int joinDelay = -1;
 
 //current robot to check in the iterator
-int iteratorCount = 0;
+static int iteratorCount = 0;
 
 // the amount of time a robot has had its BOM on for
-int bom_on_count = 0;
+static int bom_on_count = 0;
 
-void do_nothing(void) {}
-int get_nothing(void) {return -1;}
+static void do_nothing(void) {}
+static int get_nothing(void) {return -1;}
 
 #ifdef ROBOT
 #ifndef FIREFLY
-void (*bom_on_function) (void) = bom_on;
-void (*bom_off_function) (void) = bom_off;
-int (*get_max_bom_function) (void) = get_max_bom;
+static void (*bom_on_function) (void) = bom_on;
+static void (*bom_off_function) (void) = bom_off;
+static int (*get_max_bom_function) (void) = get_max_bom;
 #else
-void (*bom_on_function) (void) = do_nothing;
-void (*bom_off_function) (void) = do_nothing;
-int (*get_max_bom_function) (void) = get_nothing;
+static void (*bom_on_function) (void) = do_nothing;
+static void (*bom_off_function) (void) = do_nothing;
+static int (*get_max_bom_function) (void) = get_nothing;
 #endif
 #else
-void (*bom_on_function) (void) = do_nothing;
-void (*bom_off_function) (void) = do_nothing;
-int (*get_max_bom_function) (void) = get_nothing;
+static void (*bom_on_function) (void) = do_nothing;
+static void (*bom_off_function) (void) = do_nothing;
+static int (*get_max_bom_function) (void) = get_nothing;
 #endif
 
-PacketGroupHandler wl_token_ring_handler =
-		{WL_TOKEN_RING_GROUP, wl_token_ring_timeout_handler,
+static PacketGroupHandler wl_token_ring_handler =
+	{WL_TOKEN_RING_GROUP, wl_token_ring_timeout_handler,
 		wl_token_ring_response_handler, wl_token_ring_receive_handler,
 		wl_token_ring_cleanup};
 
@@ -135,7 +134,7 @@
  * Initialize the token ring packet group and register it with the
  * wireless library. The robot will not join a token ring.
  **/
-void wl_token_ring_register()
+int wl_token_ring_register()
 {
 	if (wl_get_xbee_id() > 0xFF)
 	{
@@ -144,7 +143,7 @@
 		WL_DEBUG_PRINT("XBee ID must be single byte for token ring, is ");
 		WL_DEBUG_PRINT_INT(wl_get_xbee_id());
 		WL_DEBUG_PRINT(".\r\n");
-		return;
+		return -1;
 	}
 
 	sensorMatrix = sensor_matrix_create();
@@ -152,6 +151,8 @@
 	sensor_matrix_set_in_ring(sensorMatrix, wl_get_xbee_id(), 0);
 
 	wl_register_packet_group(&wl_token_ring_handler);
+
+	return 0;
 }
 
 /**
@@ -193,7 +194,7 @@
 /**
  * Called approximately every quarter second by the wireless library.
  **/
-void wl_token_ring_timeout_handler()
+static void wl_token_ring_timeout_handler()
 {
 	//someone is not responding, assume they are dead
 	if (deathDelay == 0)
@@ -251,7 +252,7 @@
  * @param frame the frame number assigned when the packet was sent
  * @param received 1 if the packet was received, 0 otherwise
  **/
-void wl_token_ring_response_handler(int frame, int received)
+static void wl_token_ring_response_handler(int frame, int received)
 {
 	if (!received)
 	{
@@ -266,8 +267,7 @@
  * @param packet the data in the packet
  * @param length the length of the packet in bytes
  **/
-void wl_token_ring_receive_handler(char type, int source, unsigned char* packet,
-							int length)
+static void wl_token_ring_receive_handler(char type, int source, unsigned char* packet, int length)
 {
 	switch (type)
 	{
@@ -334,8 +334,10 @@
 int wl_token_get_sensor_reading(int source, int dest)
 {
 	if (wl_token_is_robot_in_ring(dest) &&
-			(source == wl_get_xbee_id() || wl_token_is_robot_in_ring(source)))
+			(source == wl_get_xbee_id() || wl_token_is_robot_in_ring(source))) {
 		return sensor_matrix_get_reading(sensorMatrix, source, dest);
+	}
+
 	return -1;
 }
 
@@ -360,7 +362,7 @@
  *		reading for that robot, repeated for sensorDataLength bytes
  * @param sensorDataLength the length in bytes of sensorData
  */
-void wl_token_pass_receive(int source, char nextRobot, unsigned char* sensorData, int sensorDataLength)
+static void wl_token_pass_receive(int source, char nextRobot, unsigned char* sensorData, int sensorDataLength)
 {
 	int i, j;
 
@@ -705,12 +707,15 @@
 void wl_token_iterator_begin(void)
 {
 	int i = 0;
-	iteratorCount = 0;
-	while (!sensor_matrix_get_in_ring(sensorMatrix, i) &&
-			i < sensor_matrix_get_size(sensorMatrix))
+
+	while (!sensor_matrix_get_in_ring(sensorMatrix, i) && i < sensor_matrix_get_size(sensorMatrix)) {
 		i++;
-	if (i == sensor_matrix_get_size(sensorMatrix))
+	}
+
+	if (i == sensor_matrix_get_size(sensorMatrix)) {
 		i = -1;
+	}
+
 	iteratorCount = i;
 }
 
@@ -738,15 +743,20 @@
 int wl_token_iterator_next(void)
 {
 	int result = iteratorCount;
-	if (result < 0)
+	if (result < 0) {
 		return result;
+	}
 
 	iteratorCount++;
-	while (!sensor_matrix_get_in_ring(sensorMatrix, iteratorCount) &&
-		iteratorCount < sensor_matrix_get_size(sensorMatrix))
+	while (!sensor_matrix_get_in_ring(sensorMatrix, iteratorCount)
+		&& iteratorCount < sensor_matrix_get_size(sensorMatrix)) {
 		iteratorCount++;
-	if (iteratorCount == sensor_matrix_get_size(sensorMatrix))
+	}
+
+	if (iteratorCount == sensor_matrix_get_size(sensorMatrix)) {
 		iteratorCount = -1;
+	}
+
 	return result;
 }
 
Index: trunk/code/projects/libwireless/lib/wireless.h
===================================================================
--- trunk/code/projects/libwireless/lib/wireless.h	(revision 417)
+++ trunk/code/projects/libwireless/lib/wireless.h	(revision 418)
@@ -118,7 +118,7 @@
 } PacketGroupHandler;
 
 /**@brief Initialize the wireless library **/
-int wl_init();
+int wl_init(void);
 /**@brief Uninitialize the wireless library **/
 void wl_terminate(void);
 /**@brief Perform wireless library functionality **/
@@ -129,22 +129,20 @@
 void wl_unregister_packet_group(PacketGroupHandler* h);
 
 /**@brief Send a packet to a specific robot in any PAN **/
-void wl_send_robot_to_robot_global_packet(char group, char type,
-		char* data, int len, int dest, char frame);
+int wl_send_robot_to_robot_global_packet(char group, char type, char* data, int len, int dest, char frame);
 /**@brief Send a packet to a specific robot in our PAN **/
-void wl_send_robot_to_robot_packet(char group, char type, char* data, int len, int dest, char frame);
+int wl_send_robot_to_robot_packet(char group, char type, char* data, int len, int dest, char frame);
 /**@brief Send a packet to all robots **/
 int wl_send_global_packet(char group, char type, char* data, int len, char frame);
 /**@brief Send a packet to all robots in our PAN **/
-void wl_send_pan_packet(char group, char type,
-		char* data, int len, char frame);
+void wl_send_pan_packet(char group, char type, char* data, int len, char frame);
 
 /**@brief Set the PAN we are using **/
-void wl_set_pan(int pan);
+int wl_set_pan(int pan);
 /**@brief Get the PAN we are using **/
 int wl_get_pan(void);
 /**@brief Set the channel we are using **/
-void wl_set_channel(int channel);
+int wl_set_channel(int channel);
 /**@brief Get the channel we are using **/
 int wl_get_channel(void);
 /**@brief Get the 16-bit address of the XBee module **/
Index: trunk/code/projects/libwireless/lib/xbee.c
===================================================================
--- trunk/code/projects/libwireless/lib/xbee.c	(revision 417)
+++ trunk/code/projects/libwireless/lib/xbee.c	(revision 418)
@@ -70,32 +70,32 @@
 
 /*I/O Functions*/
 static int xbee_send(char* buf, int size);
-static void xbee_send_string(char* c);
+static int xbee_send_string(char* c);
 
 #ifndef ROBOT
-void xbee_read(char* buf, int size);
+static int xbee_read(char* buf, int size);
 #endif
 
 /*Command Mode Functions
  * Called during initialization.
  */
-static void xbee_enter_command_mode(void);
-static void xbee_exit_command_mode(void);
-static void xbee_enter_api_mode(void);
-static void xbee_exit_api_mode(void);
+static int xbee_enter_command_mode(void);
+static int xbee_exit_command_mode(void);
+static int xbee_enter_api_mode(void);
+static int xbee_exit_api_mode(void);
 static void xbee_wait_for_string(char* s, int len);
 static void xbee_wait_for_ok(void);
 
 /*API Mode Functions*/
 
-int xbee_handle_packet(char* packet, int len);
-void xbee_handle_at_command_response(char* command, char result, char* extra, int extraLen);
-void xbee_handle_status(char status);
-int xbee_verify_checksum(char* packet, int len);
-char xbee_compute_checksum(char* packet, int len);
-void xbee_send_frame(char* buf, int len);
-void xbee_send_read_at_command(char* command);
-void xbee_send_modify_at_command(char* command, char* value);
+static int xbee_handle_packet(char* packet, int len);
+static void xbee_handle_at_command_response(char* command, char result, char* extra, int extraLen);
+static void xbee_handle_status(char status);
+static int xbee_verify_checksum(char* packet, int len);
+static char xbee_compute_checksum(char* packet, int len);
+static int xbee_send_frame(char* buf, int len);
+static int xbee_send_read_at_command(char* command);
+static int xbee_send_modify_at_command(char* command, char* value);
 
 /*Global Variables*/
 
@@ -116,15 +116,15 @@
 
 
 //used to store packets as they are read
-char xbee_buf[128];
-int currentBufPos = 0;
+static char xbee_buf[128];
+static int currentBufPos = 0;
 
 //XBee status
-unsigned int xbee_panID = XBEE_PAN_DEFAULT;
-unsigned int xbee_pending_panID = XBEE_PAN_DEFAULT;
-int xbee_channel = XBEE_CHANNEL_DEFAULT;
-int xbee_pending_channel = XBEE_CHANNEL_DEFAULT;
-unsigned int xbee_address = 0;
+static unsigned int xbee_panID = XBEE_PAN_DEFAULT;
+static unsigned int xbee_pending_panID = XBEE_PAN_DEFAULT;
+static int xbee_channel = XBEE_CHANNEL_DEFAULT;
+static int xbee_pending_channel = XBEE_CHANNEL_DEFAULT;
+static unsigned int xbee_address = 0;
 
 /*Function Implementations*/
 
@@ -166,15 +166,21 @@
 
 #else
 
+// Computer code
+
 /**
  * Thread that listens to the xbee.
  **/
-void* listen_to_xbee(void* x)
+static void* listen_to_xbee(void* x)
 {
 	char c;
 	while (1)
 	{
-		xbee_read(&c, 1);
+		if (xbee_read(&c, 1) != 0) {
+			fprintf(stderr, "xbee_read failed.\n");
+			return NULL;
+		}
+
 		arrival_buf[buffer_last] = c;
 		int t = buffer_last + 1;
 		if (t == XBEE_BUFFER_SIZE)
@@ -187,7 +193,8 @@
 
 		usleep(1000);
 	}
-	return 0;
+
+	return NULL;
 }
 
 #endif
@@ -258,11 +265,22 @@
 	}
 #endif
 
-	xbee_enter_command_mode();
-	xbee_enter_api_mode();
-	xbee_exit_command_mode();
-	xbee_send_read_at_command("MY");
+	if (xbee_enter_command_mode() != 0) {
+		return -1;
+	}
 
+	if (xbee_enter_api_mode() != 0) {
+		return -1;
+	}
+
+	if (xbee_exit_command_mode() != 0) {
+		return -1;
+	}
+
+	if (xbee_send_read_at_command("MY")) {
+		return -1;
+	}
+
 	//wait to return until the address is set
 	while (xbee_address == 0) xbee_get_packet(NULL);
 
@@ -289,13 +307,18 @@
  * @param buf the buffer of data to send
  * @param size the number of bytes to send
  **/
-int xbee_send(char* buf, int size)
+static int xbee_send(char* buf, int size)
 {
-	#ifdef ROBOT
+#ifdef ROBOT
 	int i;
-	for (i = 0; i < size; i++)
+	for (i = 0; i < size; i++) {
 		xbee_putc(buf[i]);
-	#else
+	}
+
+	return 0;
+
+#else
+
 	int ret = write(xbee_stream, buf, size);
 	//success
 	if (ret == size)
@@ -313,10 +336,8 @@
 	}
 
 	//write was interrupted after writing ret bytes
-	xbee_send(buf + ret, size - ret);
-	#endif
-
-	return 0;
+	return xbee_send(buf + ret, size - ret);
+#endif
 }
 
 /**
@@ -324,16 +345,20 @@
  *
  * @param c the string to send to the XBEE
  **/
-void xbee_send_string(char* c)
+static int xbee_send_string(char* c)
 {
-	xbee_send(c, strlen(c));
+	return xbee_send(c, strlen(c));
 }
 
 #ifndef ROBOT
-void xbee_read(char* buf, int size)
+static int xbee_read(char* buf, int size)
 {
-	if (read(xbee_stream, buf, size) == -1)
+	if (read(xbee_stream, buf, size) == -1) {
 		printf("Failed to read from xbee.\r\n");
+		return -1;
+	}
+
+	return 0;
 }
 #endif
 
@@ -340,36 +365,50 @@
 /**
  * Enter into command mode.
  **/
-static void xbee_enter_command_mode()
+static int xbee_enter_command_mode()
 {
-	xbee_send_string("+++");
+	if (xbee_send_string("+++") != 0) {
+		return -1;
+	}
+
 	xbee_wait_for_ok();
+
+	return 0;
 }
 
 /**
  * Exit from command mode.
  **/
-static void xbee_exit_command_mode()
+static int xbee_exit_command_mode()
 {
-	xbee_send_string("ATCN\r");
+	if (xbee_send_string("ATCN\r") != 0) {
+		return -1;
+	}
+
 	xbee_wait_for_ok();
+
+	return 0;
 }
 
 /**
  * Enter API mode.
  **/
-static void xbee_enter_api_mode()
+static int xbee_enter_api_mode()
 {
-	xbee_send_string("ATAP 1\r");
+	if (xbee_send_string("ATAP 1\r") != 0) {
+		return -1;
+	}
 	xbee_wait_for_ok();
+
+	return 0;
 }
 
 /**
  * Exit API mode. (warning - does not check for response)
  **/
-static void xbee_exit_api_mode()
+static int xbee_exit_api_mode()
 {
-	xbee_send_string("ATAP 0\r");
+	return xbee_send_string("ATAP 0\r");
 }
 
 /**
@@ -460,7 +499,7 @@
  * @param len the size in bytes of the packet data
  *
  **/
-void xbee_send_frame(char* buf, int len)
+static int xbee_send_frame(char* buf, int len)
 {
 	char prefix[3];
 	prefix[0] = XBEE_FRAME_START;
@@ -467,9 +506,20 @@
 	prefix[1] = (len & 0xFF00) >> 8;
 	prefix[2] = len & 0xFF;
 	char checksum = xbee_compute_checksum(buf, len);
-	xbee_send(prefix, 3);
-	xbee_send(buf, len);
-	xbee_send(&checksum, 1);
+
+	if (xbee_send(prefix, 3) != 0) {
+		return -1;
+	}
+	
+	if (xbee_send(buf, len) != 0) {
+		return -1;
+	}
+
+	if (xbee_send(&checksum, 1) != 0) {
+		return -1;
+	}
+
+	return 0;
 }
 
 /**
@@ -479,9 +529,9 @@
  * use ID to read the PAN ID and MY to return the XBee ID.
  * See the XBee reference guide for a complete listing.
  **/
-void xbee_send_read_at_command(char* command)
+static int xbee_send_read_at_command(char* command)
 {
-	xbee_send_modify_at_command(command, NULL);
+	return xbee_send_modify_at_command(command, NULL);
 }
 
 /**
@@ -491,7 +541,7 @@
  * @param value the value to pass as a parameter
  * (or NULL if there is no parameter)
  **/
-void xbee_send_modify_at_command(char* command, char* value)
+static int xbee_send_modify_at_command(char* command, char* value)
 {
 	char buf[16];
 	int i;
@@ -507,12 +557,15 @@
 		if (valueLen > 8)
 		{
 			WL_DEBUG_PRINT("AT Command too large.\r\n");
-			return;
+			return -1;
 		}
-		for (i = 0; i < valueLen; i++)
+
+		for (i = 0; i < valueLen; i++) {
 			buf[4 + i] = value[i];
+		}
 	}
-	xbee_send_frame(buf, 4 + valueLen);
+
+	return xbee_send_frame(buf, 4 + valueLen);
 }
 
 /**
@@ -630,20 +683,22 @@
 			// check if buffer is empty
 			if (buffer_first == buffer_last)
 				return -1;
+		} while (arrival_buf[buffer_first++] != XBEE_FRAME_START);
+
+		if (buffer_first == XBEE_BUFFER_SIZE) {
+			buffer_first = 0;
 		}
-		while (arrival_buf[buffer_first++] != XBEE_FRAME_START);
-		if (buffer_first == XBEE_BUFFER_SIZE)
-			buffer_first = 0;
 		xbee_buf[0] = XBEE_FRAME_START;
 		currentBufPos++;
 	}
 
 	int len = -1;
-	if (currentBufPos >= 3)
+	if (currentBufPos >= 3) {
 		len = (int)xbee_buf[2] + ((int)xbee_buf[1] << 8);
+	}
 
 	while (len == -1 //packet length has not been read yet
-			|| currentBufPos < len + 4)
+		|| currentBufPos < len + 4)
 	{
 		if (currentBufPos == 3)
 		{
@@ -655,12 +710,15 @@
 				return -1;
 			}
 		}
+
 		// check if buffer is empty
-		if (buffer_first == buffer_last)
+		if (buffer_first == buffer_last) {
 			return -1;
+		}
 		xbee_buf[currentBufPos++] = arrival_buf[buffer_first++];
-		if (buffer_first == XBEE_BUFFER_SIZE)
+		if (buffer_first == XBEE_BUFFER_SIZE) {
 			buffer_first = 0;
+		}
 	}
 
 	currentBufPos = 0;
@@ -672,15 +730,19 @@
 	}
 
 	//we will take care of the packet
-	if (xbee_handle_packet(xbee_buf + 3, len))
+	if (xbee_handle_packet(xbee_buf + 3, len)) {
 		return -1;
+	}
 
-	if (dest == NULL)
+	if (dest == NULL) {
 		return -1;
+	}
 
 	int i;
-	for (i = 3; i < len + 3; i++)
+	for (i = 3; i < len + 3; i++) {
 		dest[i - 3] = xbee_buf[i];
+	}
+
 	return len;
 }
 
@@ -724,8 +786,7 @@
  * @param extra the hex value of the requested register
  * @param extraLen the length in bytes of extra
  **/
-void xbee_handle_at_command_response(char* command, char result,
-	char* extra, int extraLen)
+static void xbee_handle_at_command_response(char* command, char result, char* extra, int extraLen)
 {
 	if (result == 1)
 	{
@@ -757,10 +818,14 @@
 
 	if (command[0] == 'M' && command[1] == 'Y' && extraLen != 0)
 	{
+//							printf("reading xbee_address\n");
+		
 		xbee_address = 0;
 		int i;
-		for (i = 0; i < extraLen; i++)
+		for (i = 0; i < extraLen; i++) {
 			xbee_address = (xbee_address << 8) + extra[i];
+		}
+//							printf("xbee address is: %d\n", xbee_address);
 
 		WL_DEBUG_PRINT("XBee address is ");
 		WL_DEBUG_PRINT_INT(xbee_address);
@@ -786,7 +851,7 @@
  *
  * @return 1 if we have handled the packet, 0 otherwise
  */
-int xbee_handle_packet(char* packet, int len)
+static int xbee_handle_packet(char* packet, int len)
 {
 	char command[3] = {1, 2, 3};
 	if (len <= 0) //this should not happend
@@ -804,8 +869,7 @@
 			command[0] = packet[2];
 			command[1] = packet[3];
 			command[2] = 0;
-			xbee_handle_at_command_response(command,
-				packet[4], packet + 5, len - 5);
+			xbee_handle_at_command_response(command, packet[4], packet + 5, len - 5);
 			return 1;
 	}
 	return 0;
@@ -816,7 +880,7 @@
  *
  * @param id the new personal area network (PAN) id
  **/
-void xbee_set_pan_id(int id)
+int xbee_set_pan_id(int id)
 {
 	char s[3];
 	s[0] = (id >> 8) & 0xFF;
@@ -823,7 +887,7 @@
 	s[1] = id & 0xFF;
 	s[2] = 0;
 	xbee_pending_panID = id;
-	xbee_send_modify_at_command("ID", s);
+	return xbee_send_modify_at_command("ID", s);
 }
 
 /**
@@ -845,18 +909,20 @@
  *
  * @see xbee_get_channel
  **/
-void xbee_set_channel(int channel)
+int xbee_set_channel(int channel)
 {
 	if (channel < 0x0B || channel > 0x1A)
 	{
 		WL_DEBUG_PRINT("Channel out of range.\r\n");
-		return;
+		return -1;
 	}
+
 	char s[3];
 	s[0] = channel & 0xFF;
 	s[1] = 0;
 	xbee_pending_channel = channel;
-	xbee_send_modify_at_command("CH", s);
+
+	return xbee_send_modify_at_command("CH", s);
 }
 
 /**
Index: trunk/code/projects/libwireless/lib/wl_token_ring.h
===================================================================
--- trunk/code/projects/libwireless/lib/wl_token_ring.h	(revision 417)
+++ trunk/code/projects/libwireless/lib/wl_token_ring.h	(revision 418)
@@ -47,7 +47,7 @@
  **/
 
 /**@brief Register the token ring group with the wireless library.**/
-void wl_token_ring_register(void);
+int wl_token_ring_register(void);
 /**@brief Unregister the token ring group with the wirelss library.**/
 void wl_token_ring_unregister(void);
 /**@brief Set the functions called to turn the bom on and off.**/
Index: trunk/code/projects/libwireless/lib/xbee.h
===================================================================
--- trunk/code/projects/libwireless/lib/xbee.h	(revision 417)
+++ trunk/code/projects/libwireless/lib/xbee.h	(revision 418)
@@ -74,7 +74,7 @@
 #define XBEE_RX 0x81
 
 /**@brief Initialize the XBee library **/
-int xbee_lib_init();
+int xbee_lib_init(void);
 /**@brief Uninitialize the XBee library **/
 void xbee_terminate(void);
 /**@brief Get a packet from the XBee **/
@@ -82,11 +82,11 @@
 /**@brief Send a packet to the XBee **/
 int xbee_send_packet(char* packet, int len, int dest, char options, char frame);
 /**@brief Set the PAN ID for the XBee **/
-void xbee_set_pan_id(int id);
+int xbee_set_pan_id(int id);
 /**@brief Get the XBee's PAN ID **/
 unsigned int xbee_get_pan_id(void);
 /**@brief Set the channel the XBee is currently using **/
-void xbee_set_channel(int channel);
+int xbee_set_channel(int channel);
 /**@brief Get the channel the XBee is currently using **/
 int xbee_get_channel(void);
 /**@brief Get the XBee's 16-bit address **/
Index: trunk/code/projects/libwireless/lib/sensor_matrix.c
===================================================================
--- trunk/code/projects/libwireless/lib/sensor_matrix.c	(revision 417)
+++ trunk/code/projects/libwireless/lib/sensor_matrix.c	(revision 418)
@@ -1,6 +1,6 @@
 /**
  * Copyright (c) 2007 Colony Project
- * 
+ *
  * Permission is hereby granted, free of charge, to any person
  * obtaining a copy of this software and associated documentation
  * files (the "Software"), to deal in the Software without
@@ -9,10 +9,10 @@
  * copies of the Software, and to permit persons to whom the
  * Software is furnished to do so, subject to the following
  * conditions:
- * 
+ *
  * The above copyright notice and this permission notice shall be
  * included in all copies or substantial portions of the Software.
- * 
+ *
  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
  * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
  * OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
@@ -41,7 +41,7 @@
 #define DEFAULT_SENSOR_MATRIX_SIZE 20
 
 /*Sensor Matrix Functions*/
-void sensor_matrix_expand(SensorMatrix* m, int nextSize);
+static void sensor_matrix_expand(SensorMatrix* m, int nextSize);
 
 /**
  * Initializes the sensor matrix.
@@ -52,7 +52,7 @@
 {
 	SensorMatrix* m;
 	int i;
-	
+
 	m = (SensorMatrix*)malloc(sizeof(SensorMatrix));
 	if (!m)
 	{
@@ -79,7 +79,7 @@
 		WL_DEBUG_PRINT("Out of memory - create sensor matrix 2.\r\n");
 		return NULL;
 	}
-	
+
 	for (i = 0; i < m->size; i++)
 	{
 		m->matrix[i] = NULL;
@@ -106,7 +106,7 @@
 
 /**
  * Adds robot with XBee id id to the sensor matrix.
- * 
+ *
  * @param m the sensor matrix
  * @param id the XBee ID of the robot to add
  **/
@@ -113,11 +113,14 @@
 void sensor_matrix_add_robot(SensorMatrix* m, int id)
 {
 	int i;
-	if (id >= m->size)
+	if (id >= m->size) {
 		sensor_matrix_expand(m, id + 1);
-	if (m->matrix[id] != NULL)
+	}
+
+	if (m->matrix[id] != NULL) {
 		return;
-	
+	}
+
 	m->matrix[id] = (int*)malloc(m->size * sizeof(int));
 	if (!(m->matrix[id]))
 	{
@@ -125,9 +128,11 @@
 		return;
 	}
 
-	for (i = 0; i < m->size; i++)
-		if (m->matrix[i] != NULL)
+	for (i = 0; i < m->size; i++) {
+		if (m->matrix[i] != NULL) {
 			m->matrix[i][id] = -1;
+		}
+	}
 }
 
 /**
@@ -146,14 +151,14 @@
 		WL_DEBUG_PRINT("Removing robot not added to matrix.\r\n");
 		return;
 	}
-	
+
 	free(m->matrix[id]);
 	m->matrix[id] = NULL;
-	
+
 	for (i = 0 ; i < m->size; i++)
 		if (m->matrix[i] != NULL)
 			m->matrix[i][id] = -1;
-	
+
 	m->joined[id] = 0;
 }
 
@@ -165,11 +170,11 @@
  * @param size the new size of the sensor matrix
  **/
 //Note: this has probably not been tested, hopefully it works
-void sensor_matrix_expand(SensorMatrix* m, int nextSize)
+static void sensor_matrix_expand(SensorMatrix* m, int nextSize)
 {
 	int i, j;
 	WL_DEBUG_PRINT("Expanding sensor matrix.\r\n");
-	
+
 	int** tempMatrix = (int**)malloc(nextSize * sizeof(int*));
 	if (!tempMatrix)
 	{
@@ -176,10 +181,10 @@
 		WL_DEBUG_PRINT("Out of memory - expand matrix.\r\n");
 		return;
 	}
-	
+
 	for (i = 0; i < nextSize; i++)
 		tempMatrix[i] = NULL;
-	
+
 	//copy over old sensor data
 	for (i = 0; i < m->size; i++)
 		if (m->matrix[i] != NULL)
@@ -190,14 +195,17 @@
 				WL_DEBUG_PRINT("Out of memory - expand matrix 2.\r\n");
 				return;
 			}
-			for (j = 0; j < m->size; j++)
+			for (j = 0; j < m->size; j++) {
 				tempMatrix[i][j] = m->matrix[i][j];
-			for (j = m->size; j < nextSize; j++)
+			}
+
+			for (j = m->size; j < nextSize; j++) {
 				tempMatrix[i][j] = -1;
-			
+			}
+
 			free(m->matrix[i]);
 		}
-	
+
 	free(m->matrix);
 	m->matrix = tempMatrix;
 	m->size = nextSize;
@@ -209,12 +217,15 @@
 		WL_DEBUG_PRINT("Out of memory - expand matrix 3.\r\n");
 		return;
 	}
-	
-	for (i = 0; i < m->size; i++)
+
+	for (i = 0; i < m->size; i++) {
 		tempJoined[i] = m->joined[i];
-	for (i = m->size; i < nextSize; i++)
+	}
+
+	for (i = m->size; i < nextSize; i++) {
 		tempJoined[i] = 0;
-	
+	}
+
 	free(m->joined);
 	m->joined = tempJoined;
 }
@@ -221,7 +232,7 @@
 
 /**
  * Sets the sensor reading for robot robot to reading.
- * 
+ *
  * @param m the sensor matrix to set the reading for
  * @param observer the id of the robot who made the reading
  * @param robot the id of the robot who the reading is for
@@ -229,8 +240,10 @@
  */
 void sensor_matrix_set_reading(SensorMatrix* m, int observer, int robot, int reading)
 {
-	if (robot >= m->size || observer >= m->size || m->matrix[observer] == NULL)
+	if (robot >= m->size || observer >= m->size || m->matrix[observer] == NULL) {
 		sensor_matrix_add_robot(m, observer);
+	}
+
 	m->matrix[observer][robot] = reading;
 }
 
@@ -245,8 +258,10 @@
  **/
 int sensor_matrix_get_reading(SensorMatrix* m, int observer, int robot)
 {
-	if (observer >= m->size || robot >= m->size)
+	if (observer >= m->size || robot >= m->size) {
 		return -1;
+	}
+
 	return m->matrix[observer][robot];
 }
 
@@ -259,20 +274,28 @@
  **/
 void sensor_matrix_set_in_ring(SensorMatrix* m, int robot, int in)
 {
-	if (robot >= m->size)
+	if (robot >= m->size) {
 		sensor_matrix_expand(m, robot + 1);
-	if (in == 1)
+	}
+
+	if (in == 1) {
 		sensor_matrix_add_robot(m, robot);
-	if (in == 1 && m->joined[robot] == 0)
+	}
+
+	if (in == 1 && m->joined[robot] == 0) {
 		m->numJoined++;
-	if (in == 0 && m->joined[robot] == 1)
+	}
+
+	if (in == 0 && m->joined[robot] == 1) {
 		m->numJoined--;
+	}
+
 	m->joined[robot] = in;
 }
 
 /**
  * Checks if the given robot is in the token ring.
- * 
+ *
  * @param m the sensor matrix
  * @param robot the ID of the robot to check
  *
@@ -280,8 +303,10 @@
  **/
 int sensor_matrix_get_in_ring(SensorMatrix* m, int robot)
 {
-	if (robot >= m->size)
+	if (robot >= m->size) {
 		return -1;
+	}
+
 	return m->joined[robot];
 }
 
@@ -289,7 +314,7 @@
  * Returns the size of the sensor matrix.
  *
  * @param m the sensor matrix
- * 
+ *
  * @return the size of the sensor matrix
  **/
 int sensor_matrix_get_size(SensorMatrix* m)
@@ -309,4 +334,3 @@
 {
 	return m->numJoined;
 }
-
Index: trunk/code/projects/libwireless/lib/wireless.c
===================================================================
--- trunk/code/projects/libwireless/lib/wireless.c	(revision 417)
+++ trunk/code/projects/libwireless/lib/wireless.c	(revision 418)
@@ -168,9 +168,9 @@
  *
  * @see wl_get_pan
  **/
-void wl_set_pan(int pan)
+int wl_set_pan(int pan)
 {
-	xbee_set_pan_id(pan);
+	return xbee_set_pan_id(pan);
 }
 
 /**
@@ -192,9 +192,9 @@
  *
  * @see wl_get_channel
  **/
-void wl_set_channel(int channel)
+int wl_set_channel(int channel)
 {
-	xbee_set_channel(channel);
+	return xbee_set_channel(channel);
 }
 
 /**
@@ -229,11 +229,9 @@
  * @param dest the 16-bit address of the XBee to send the packet to
  * @param frame the frame number to see with a TX_STATUS response
  **/
-void wl_send_robot_to_robot_global_packet(char group, char type,
-		char* data, int len, int dest, char frame)
+int wl_send_robot_to_robot_global_packet(char group, char type, char* data, int len, int dest, char frame)
 {
-	wl_send_packet(group, type, data, len, dest,
-			XBEE_OPTIONS_BROADCAST_ALL_PANS, frame);
+	return wl_send_packet(group, type, data, len, dest, XBEE_OPTIONS_BROADCAST_ALL_PANS, frame);
 }
 
 /**
@@ -246,11 +244,9 @@
  * @param dest the 16-bit address of the XBee to send the packet to
  * @param frame the frame number to see with a TX_STATUS response
  **/
-void wl_send_robot_to_robot_packet(char group, char type,
-		char* data, int len, int dest, char frame)
+int wl_send_robot_to_robot_packet(char group, char type, char* data, int len, int dest, char frame)
 {
-	wl_send_packet(group, type, data, len, dest, XBEE_OPTIONS_NONE,
-			frame);
+	return wl_send_packet(group, type, data, len, dest, XBEE_OPTIONS_NONE, frame);
 }
 
 /**
@@ -388,8 +384,9 @@
 		//this only works with under 16 groups
 		int group = (int)(wl_buf[1] >> 4);
 		int success = 0;
-		if (wl_buf[2] == 0)
+		if (wl_buf[2] == 0) {
 			success = 1;
+		}
 		else
 		{
 			WL_DEBUG_PRINT("No response received.\r\n");
