Remaining timeout to stop testing threads is now calculated properly

not sure if complexity of the method is still acceptable as there is quite a lot of branching.