Factorize taskCompletion function