Nice refactoring. But this may have wrong answers because "--i", which should be "i--".

Thanks.