Added code to do per-task sampling