got it working, but without using gettimeofday()