Fix output judge bugs, and clean code