replace imperative total time calculation with a more 'scala-esk' recursive function