Refactored how output is handled.