Index: reactor.c
===================================================================
--- reactor.c	(revision 1)
+++ reactor.c	(working copy)
@@ -16,14 +16,48 @@
 rtimer_t* timer_tail = NULL;
 int e_fd = 0;
 
-struct timespec reactor_calc_time(int sec, int usec){
+static inline long cmp_time(struct timespec a, struct timespec b) {
+	if (a.tv_sec == b.tv_sec)
+		return a.tv_nsec - b.tv_nsec;
+	else
+		return a.tv_sec - b.tv_sec;
+}
+
+int timespec_subtract(struct timespec *result, struct timespec *x,
+                struct timespec *y) {
+
+        /* Perform the carry for the later subtraction by updating y. */
+        if (x->tv_nsec < y->tv_nsec) {
+                int nsec = (y->tv_nsec - x->tv_nsec) / 1000000000 + 1;
+                y->tv_nsec -= 1000000000 * nsec;
+                y->tv_sec += nsec;
+        }
+        if (x->tv_nsec - y->tv_nsec > 1000000000) {
+                int nsec = (x->tv_nsec - y->tv_nsec) / 1000000000;
+                y->tv_nsec += 1000000000 * nsec;
+                y->tv_sec -= nsec;
+        }
+
+        /* Compute the time remaining to wait.
+         *      tv_usec is certainly positive. */
+        result->tv_sec = x->tv_sec - y->tv_sec;
+        result->tv_nsec = x->tv_nsec - y->tv_nsec;
+
+        /* Return 1 if result is negative. */
+        return x->tv_sec < y->tv_sec;
+
+
+}
+
+
+struct timespec reactor_calc_time(int sec, int nsec){
 	struct timespec tv;
 	assert(sec>=0);
-	assert(usec>=0);
+	assert(nsec>=0);
 
 	tv.tv_sec = reactor_now.tv_sec + sec;
-	tv.tv_nsec = reactor_now.tv_nsec + usec*1000;
-	if (tv.tv_nsec >= 1000000000){
+	tv.tv_nsec = reactor_now.tv_nsec + nsec;
+	while (tv.tv_nsec >= 1000000000){
 		tv.tv_sec += 1;
 		tv.tv_nsec -= 1000000000;
 	}
@@ -112,13 +146,25 @@
 void reactor_run(void){
 	int numevents = 20;
 	int waittime = 0;
+	struct timespec wait;
+	struct timespec now;
+	struct timespec next;
 	int i, nfds = 0;
 	struct epoll_event* events = malloc( numevents * sizeof(struct epoll_event));
 	clock_gettime(CLOCK_MONOTONIC,&reactor_now);
 	while(1){
 		/* printf("%i\n", waittime); */
 		/*  */
-		if (timer_head && (CMP_TIME(timer_head->expire, reactor_now) < 0)){
+		if (timer_head && (cmp_time(timer_head->expire, reactor_now) < 0)){
+	
+			/*
+			printf("InstaPOP  expire=%u %u  now=%u %u   %d\n",
+					timer_head->expire.tv_sec,
+					timer_head->expire.tv_nsec,
+					reactor_now.tv_sec,
+					reactor_now.tv_nsec,
+					cmp_time(timer_head->expire, reactor_now));
+			*/
 			rtimer_t* cb = timer_head;
 			if (timer_head->next){
 				timer_head = timer_head->next;
@@ -135,8 +181,12 @@
 
 		/* Need to do this here in case the callback added a timer */
 		if (timer_head){
-			waittime = (timer_head->expire.tv_sec - reactor_now.tv_sec) * 1000;
-			waittime += (timer_head->expire.tv_nsec - reactor_now.tv_nsec)/1000000;
+			next = timer_head->expire;
+			now = reactor_now;
+			timespec_subtract(&wait, &next, &now);
+
+			waittime = wait.tv_sec * 1000 + (wait.tv_nsec / 1000000);
+			//printf("Waiting for %u %u (%d)\n", wait.tv_sec, wait.tv_nsec, waittime);
 		}else
 			waittime = -1;
 
Index: reactor.h
===================================================================
--- reactor.h	(revision 1)
+++ reactor.h	(working copy)
@@ -26,7 +26,11 @@
 	struct epoll_event evt;
 } rfd_t;
 
-struct timespec reactor_calc_time(int sec, int usec);
+int timespec_subtract(struct timespec *result, struct timespec *x,
+                struct timespec *y);
+
+/* NOTE: this is expecting a NANOsecond value now as the second parameter */
+struct timespec reactor_calc_time(int sec, int nsec);
 int reactor_init(int fd_hint);
 void reactor_add_timer(rtimer_t* cb);
 int reactor_add_fd(rfd_t* cb);
