Replaced elapsed time handler with a more readable one, ported from Obj-C.