added timing and first optimzation