added better timing code