Output appears to be finished. Made some minor optimizations.