Port to Josh's new code
Added statistics
Update statistics
Avoid crash with 0 time passing