Simplified code and added a timer to show elapsed time.