function static prevtime also needs to be thread local