updated to use gettimeofday for timer