Add THREAD_LOCAL, some other stuff
Abstract away gettimeofday and a few calls to usleep