polised and added timing with timeit