reduce code size

delete unreferenced var i, and reduce the code in if condition