updated to use formatOutput, and addressed the rest of the comments in this section.