Fix bugs and print total time.