In the done function of the first returned function did you mean to subtract t' from t' (instead of t from t')? I don't see why this would cause an exception, but it looks wrong to me and doesn't agree with the comment.