modified output method. Handle some corner cases in the process.