clean-up and refactor

* restoring i, j pointer