Use long instead of int to mesure time
Reset the timer only when a task was successful

Currently the timer is reset after each iteration (thus repeats the
minimum wait every time).