Step 7, beautify a bit, and cleanup code.