Refactored with adding functions to handle struct timeval.