Step design of compare and some code optimization.