Refactoring and fixing a bug.
Fixing bugs and output.