Add two collectOutputAndError functions