Fixed an IndexOutOfBounds bug.
Added counters for user's convenience.