Fixes bugs, cleans up output.