Cleaned up the code grouping and the output lines a little.