Fixed broken counting of total_elapsed

total_elapsed always shows time elapsed in the last function call, not the total.