added timing code (not refactored)