Removes spurious output and adjusts final output.