refactor timespent method for simplicity, correctness, error-handling, readablity