Refactor result-printing into a function.