Fix bug in logic for calling after tasks